Memory footprint of multi-dimensional arrays
Fawzi Mohamed
fmohamed at mac.com
Sat Apr 19 02:39:34 PDT 2008
On 2008-04-18 18:04:17 +0200, Ben Mitchell <Arisian at gmail.com> said:
> So, I was watching my D program eat up ~1GB of ram doing something my
> back of the envelope calculation said should only be taking a few
> hundred MB max, and I started playing around. Turns out that if I do:
>
> ubyte[][] b = new ubyte[][](3, 10485760);
>
> It takes about 30MB of main memory, as would be expected. If, on the
> other hand, I reverse the order of the indexing and do:
>
> ubyte[][] b = new ubyte[][](10485760, 3);
>
> It takes about 250MB of main memory. This seems totally absurd to me;
> I can only assume this is because it's an array of (potentially
> arbitrary size) dynamic arrays, and there's ~220MB of bookkeeping
> information being stored. Is there any way around this? Can I
> somehow tell the compiler it's a symmetric array? Can I make a dynamic
> array of static arrays of size 3? I can reverse the indexing if I have
> to, but it would make the rest of my code very counter-intuitive, and
> it just doesn't seem like it should make an order of magnitude
> difference in memory usage.
>
> - Ben
you probably want to look at the multiarray library:
http://www.dsource.org/projects/multiarray/
Fawzi
More information about the Digitalmars-d
mailing list