dynamic array memory allocation

Unknown W. Brackets unknown at simplemachines.org
Wed May 16 00:45:23 PDT 2007


If that happened, it would most likely look more like:

a.allocated = 10;

But, generally, in my experience I've found very little need to set such 
a value - as much as it seems very useful, from a logical standpoint.

Instead, I've found myself setting length to a higher-than-necessary 
value, and setting it down once I'm finished.  I use slicing a lot more 
than concatenating this way.

I suspect, performance and footprint wise, it's not much different.

-[Unknown]


Greg Weber wrote:
> I find myself wondering what actually happens when I create a dynamic array and concatenate items onto it.  I think I read in a post that memory will be over-allocated at times to avoid re-allocating.
> 
> I think it would help out a lot to have an ability to specify over-allocation.  Something like
> uint a = [];
> a.length = 3:10
> 
> Where the array length is 3, but you are guaranteed to have memory allocation for 10, so you can be guaranteed that concatenation up to ten will not need to allocate memory.  This could help in the situation where there is concatenation in a loop, and the programmer over-sizes the array before the loop and re-sizes after the loop.



More information about the Digitalmars-d mailing list