Often repeated array allocations
Dmitry Olshansky
dmitry.olsh at gmail.com
Sat Jul 20 13:22:53 PDT 2013
21-Jul-2013 00:19, Namespace пишет:
> 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. :)
5. Keep a TLS scratch pad buffer (static class member) for said
100-4000 floats and re-use it.
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list