runtime static arrays

Namespace rswhite4 at googlemail.com
Tue Nov 20 06:25:57 PST 2012


Is there any need for 'smart' or 'compressed' arrays?

In my last projects I had some situations where I need an array, 
but only for one scope. But I could not use static arrays, 
because I didn't know the size at compile time. So I used 
'alloca'. But 'alloca' has a terrible interface and in some few 
cases I had to append x elements. So I used a dynamic array. But 
dynamic arrays live longer as the lifetime of the scope. 
Furthermore dynamic arrays costs more memory as I needed, because 
the capacity of them is n * 2 + 1, but in my cases I need only n.
So what I need was an array, which lives only for one scope 
(freed memory after leaving scope) and which hasn't more 
elements/capacity as I need.

Am I wrong and dynamic arrays are the solution? Or is there need 
for such 'compressed' arrays?
Another solution would be to improve the interface of alloca, but 
it would be still not resizable.


More information about the Digitalmars-d-learn mailing list