Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 27, 2013 How to use large size array, which are shared | ||||
---|---|---|---|---|
| ||||
Hello I read: "The total size of a static array cannot exceed 16Mb. A dynamic array should be used instead for such large arrays." I want to make array which is shared but also has a large size, e.g. shared WorkerClass[numberOfWorkers] myWorkerArray; where numberOfWorkers is large. If I try to do: shared WorkerClass[] myWorkerArray; int main() { ..... myWorkerArray = new WorkerClass [numberOfWorkers]; } the compiler does not allow me to do so. My motivation is to create a global array, which I can use in multiple functions which are created using "spawn". Can you please help me. |
January 27, 2013 Re: How to use large size array, which are shared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sparsh Mittal | Solved! I did: myWorkerArray = new shared WorkerClass [numberOfWorkers]; Thanks. |
January 27, 2013 Re: How to use large size array, which are shared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sparsh Mittal | On 01/27/2013 01:44 PM, Sparsh Mittal wrote: > Hello > > I read: "The total size of a static array cannot exceed 16Mb. A > dynamic array should be used instead for such large arrays." > > I want to make array which is shared but also has a large size, > e.g. > > shared WorkerClass[numberOfWorkers] myWorkerArray; > > where numberOfWorkers is large. > > If I try to do: > > shared WorkerClass[] myWorkerArray; > int main() > { > ..... > myWorkerArray = new WorkerClass [numberOfWorkers]; shared is a part of the type: myWorkerArray = new shared(WorkerClass)[numberOfWorkers]; Alternatively, you can initialize myWorkerArray in a 'static this' block: class WorkerClass {} enum size_t numberOfWorkers = 10; shared WorkerClass[] myWorkerArray; static this() { myWorkerArray = new shared(WorkerClass)[numberOfWorkers]; } void main() {} > Can you please help me. Please also consider the D.learn newsgroup. Such threads are very helpful on that newsgroup as well. :) Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html |
January 27, 2013 Re: How to use large size array, which are shared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Thanks a lot. Sure, I post such questions on that forum. |
January 27, 2013 Re: How to use large size array, which are shared | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | > shared WorkerClass[] myWorkerArray;
>
> static this()
> {
> myWorkerArray = new shared(WorkerClass)[numberOfWorkers];
> }
This should probably be "shared static this()". I'm guessing one would want this to run once before main(), not every time a thread is started.
|
Copyright © 1999-2021 by the D Language Foundation