proposal: capacity variable for dynamic arrays

Derek Parnell derek at psych.ward
Mon Jul 10 12:37:19 PDT 2006


On Tue, 11 Jul 2006 02:22:30 +1000, Ameer Armaly  
<ameer_armaly at hotmail.com> wrote:

> Right now dynamic arrays use length to resize and handle memmory  
> allocation.
> This is a bit limiting as far as the old memmory  reservation problem as
> well as a few other things.

If the behaviour in D changed (dare I say 'fixed') such that assigning an  
array length to zero would *not* also set the pointer to null, then the  
capacity idea can be easily implemented as ...

   int[] arr;
   . . .
   arr.length = capacity;
   arr.length = 0;

This would assign RAM to the required size and by setting length back to  
zero, it would be kept and 'resused' as the array elements where added.

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d mailing list