Array access via pointer

Simen kjaeraas simen.kjaras at
Sun May 30 15:02:45 PDT 2010

Robert <robert.muench at> wrote:

> Ok, I thought that the structure was a bit more flat like:
> typedef struct array {
> 	int length;
> 	int[1..length] data;
> }
> Avoiding one indirection as it could be assumed that the  
> memory-allocator / GC will return a continous piece for the array. But  
> of course resizing and reallocation would be a bit more complicated.

In addition to the problems you mention, there is also that of
alignment requirements. Even if the memory lost is only 4 bytes for
that int of length, if the data requires alignment of N bytes, the
actual loss will be N bytes. This is of course much more of a
problem with smaller than with larger arrays.


More information about the Digitalmars-d mailing list