Array length & allocation question

BCS BCS at pathlink.com
Thu Jun 8 10:30:29 PDT 2006


Robert Atkinson wrote:
> Quick question concerning Array lengths and memory allocations.
> 
> When an array.length = array.length + 1 (or length - 1) happens, does the system
> only increase (decrease) the memory allocation by 1 [unit] or does it internally
> mantain a buffer and try to minimise the resizing of the array?
> 
> I think I can remember seeing posts saying to maintain the buffer yourself and
> other posts saying it was done automatically behind the scenes.
> 
> 
> 
> 
Even if the buffer is there I would think that it would be faster to do 
it your self because you have more information to decide how to do it


char[] first = "foo bar"

func(first[0..3]);


char[] func(char[] inp)
{
		// first time around can't extend in place
		// logic to check this would be costly
	while(go())
		inp.length = inp.length+1;

	return inp;		
}



More information about the Digitalmars-d-learn mailing list