Often repeated array allocations

Namespace rswhite4 at googlemail.com
Sat Jul 20 13:46:32 PDT 2013


On Saturday, 20 July 2013 at 20:22:56 UTC, Dmitry Olshansky wrote:
> 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.

TLS scratch pad buffer?


More information about the Digitalmars-d-learn mailing list