Maximum array size

Lionello Lunesu lio at lunesu.remove.com
Wed Apr 26 00:15:05 PDT 2006


gassa at mail.ru wrote:
> Hi!
> 
> What is the 16M limit on the array length for?
> Recently I needed more space but when I declared a ~25M array of ubytes I
> quickly ran into a compile error saying
>> file.d(5): index 25000000 overflow for static array
> 
> An investigation got me to lines 1592-1593 of src/dmd/mtype.c stating
>> if (n2 >= 0x1000000)    // put a 'reasonable' limit on it
>>     goto Loverflow;
> with the above message printed at Loverflow.
> 
> I wonder what's the 'reason' on that limit.


I've put the same limit in my own array template I use for C++ projects. 
  My reasoning was that you shouldn't be using a dynamic array for such 
huge memory blocks because of the potential costly resize. The limit 
helped me catch some bugs where array were being used and caused a 
significant performance bottleneck. I rewrote those parts with a simple 
malloc/free or VirtualAlloc. In D there might be the added complexities 
of the garbage collector. Remember that it keeps scanning the allocated 
memory for pointers. For these huge blocks it's better to use some other 
memory allocation scheme.

L.



More information about the Digitalmars-d mailing list