Re: Allocating large 2D array in D

2013-02-07 Thread Denis Shelomovskij
04.02.2013 20:54, bearophile пишет: Steven Schveighoffer: Wow, this is something I didn't know was possible. Very useful! It's it cute when you use a language almost daily for few years, and then you see a new way to allocate built-in arrays? :-) Just a small obvious note that this trick w

Re: Allocating large 2D array in D

2013-02-05 Thread H. S. Teoh
On Tue, Feb 05, 2013 at 07:38:40PM +0100, bearophile wrote: > H. S. Teoh: > > >Added to wiki: http://wiki.dlang.org/Dense_multidimensional_arrays > > It contains: > > enum columns = 100; > int rows = 100; > double[gridSize][] gridInfo = new double[columns][](rows); > > > gridSize is undefined.

Re: Allocating large 2D array in D

2013-02-05 Thread bearophile
H. S. Teoh: Added to wiki: http://wiki.dlang.org/Dense_multidimensional_arrays It contains: enum columns = 100; int rows = 100; double[gridSize][] gridInfo = new double[columns][](rows); gridSize is undefined. I suggest to write something like: enum nColumns = 100; int nRows = 120; double[

Re: Allocating large 2D array in D

2013-02-05 Thread H. S. Teoh
On Mon, Feb 04, 2013 at 04:58:36PM +0100, bearophile wrote: > monarch_dodra: > > >If all (but last of) the dimensions are known at compile time, > >then you can dynamically allocate an array of fixed sized arrays: > > > >// > >enum size_t gridSize = 4_000; > >enum size_t total = gridSize * g

Re: Allocating large 2D array in D

2013-02-04 Thread monarch_dodra
On Monday, 4 February 2013 at 22:02:48 UTC, bearophile wrote: monarch_dodra: Ideally, I wish we could allocate static arrays on the heap easily: "int[2]* p = new int[2]()" To do that I wrap the array inside a static struct: struct Arr { int[2] a; } Arr* data = new Arr; writeln(data.a[

Re: Allocating large 2D array in D

2013-02-04 Thread bearophile
See also: http://d.puremagic.com/issues/show_bug.cgi?id=9265 Bye, bearophile

Re: Allocating large 2D array in D

2013-02-04 Thread bearophile
monarch_dodra: Ideally, I wish we could allocate static arrays on the heap easily: "int[2]* p = new int[2]()" To do that I wrap the array inside a static struct: struct Arr { int[2] a; } Arr* data = new Arr; writeln(data.a[1]); Anybody know why this doesn't work? Maybe it's just a

Re: Allocating large 2D array in D

2013-02-04 Thread monarch_dodra
On Monday, 4 February 2013 at 16:54:37 UTC, bearophile wrote: Steven Schveighoffer: Wow, this is something I didn't know was possible. Very useful! It's it cute when you use a language almost daily for few years, and then you see a new way to allocate built-in arrays? :-) Bye, bearophile

Re: Allocating large 2D array in D

2013-02-04 Thread Simen Kjaeraas
On 2013-13-04 17:02, Steven Schveighoffer wrote: BTW, "all (but last of) the dimensions" isn't correct, you know them all in your example, and it looks great! I believe his point was that this also works if you don't know the last dimension beforehand. -- Simen

Re: Allocating large 2D array in D

2013-02-04 Thread bearophile
Steven Schveighoffer: Wow, this is something I didn't know was possible. Very useful! It's it cute when you use a language almost daily for few years, and then you see a new way to allocate built-in arrays? :-) Bye, bearophile

Re: Allocating large 2D array in D

2013-02-04 Thread Steven Schveighoffer
On Mon, 04 Feb 2013 10:58:36 -0500, bearophile wrote: monarch_dodra: If all (but last of) the dimensions are known at compile time, then you can dynamically allocate an array of fixed sized arrays: // enum size_t gridSize = 4_000; enum size_t total = gridSize * gridSize; static ass

Re: Allocating large 2D array in D

2013-02-04 Thread Sparsh Mittal
It's not a big deal, but indexing *might* be a little slower with this scheme. Thanks a lot for your reply. It was extremely useful, since I am optimizing for performance.

Re: Allocating large 2D array in D

2013-02-04 Thread bearophile
monarch_dodra: If all (but last of) the dimensions are known at compile time, then you can dynamically allocate an array of fixed sized arrays: // enum size_t gridSize = 4_000; enum size_t total = gridSize * gridSize; static assert (total == 16_000_000); //16 million doubles total stati

Re: Allocating large 2D array in D

2013-02-04 Thread monarch_dodra
On Monday, 4 February 2013 at 15:23:20 UTC, Sparsh Mittal wrote: I am allocating 2d array as: double[gridSize][gridSize] gridInfo; which works for small dimension, but for large dimension, 16Mb limit comes. Would you please tell me how do allocate a large 2d array (which has to be done as a

Re: Allocating large 2D array in D

2013-02-04 Thread Sparsh Mittal
Thanks for your prompt reply. It was very helpful.

Re: Allocating large 2D array in D

2013-02-04 Thread bearophile
Sparsh Mittal: I am allocating 2d array as: double[gridSize][gridSize] gridInfo; which works for small dimension, but for large dimension, 16Mb limit comes. Walter has decided to introduce a very low limit for the size of static arrays. (Both Clang and G++ support larger ones). Would yo

Allocating large 2D array in D

2013-02-04 Thread Sparsh Mittal
I am allocating 2d array as: double[gridSize][gridSize] gridInfo; which works for small dimension, but for large dimension, 16Mb limit comes. Would you please tell me how do allocate a large 2d array (which has to be done as a dynamic array)? It is a square grid and dimensions are already k