digitalmars.D - How to use large size array, which are shared
- Sparsh Mittal (18/18) Jan 27 2013 Hello
- Sparsh Mittal (3/3) Jan 27 2013 Solved! I did:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/33) Jan 27 2013 shared is a part of the type:
- Sparsh Mittal (1/1) Jan 27 2013 Thanks a lot. Sure, I post such questions on that forum.
- jerro (3/8) Jan 27 2013 This should probably be "shared static this()". I'm guessing one
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.
Jan 27 2013
Solved! I did: myWorkerArray = new shared WorkerClass [numberOfWorkers]; Thanks.
Jan 27 2013
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
Jan 27 2013
Thanks a lot. Sure, I post such questions on that forum.
Jan 27 2013
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.
Jan 27 2013