Often repeated array allocations

Namespace rswhite4 at googlemail.com
Sat Jul 20 13:19:01 PDT 2013


Let us assume we have a method of a class which is used often and 
the method is called periodically and must allocate every time a 
array between 100 and 4000 elements. What would you do?

1. Simple: float[] array;
2. Reserve: float[] array; array.reserve(N); /// N is a parameter 
value
3. Use manual memory allocation (e.g. with malloc) and free the 
memory immediately at the end of the scope.
4. Use stack allocated memory (But maybe 4000 is too big?)

Currently I would prefer #3, the manual memory allocation because 
I can then control when _exactly_ the memory is released. But I 
want to hear other opinions. :)


More information about the Digitalmars-d-learn mailing list