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. :)

Reply via email to