Dynamic memory allocation approaches for C++ apps - pros and cons

Robert S. Grimes rsg at alum.mit.edu
Mon Dec 3 00:41:38 UTC 2007


Angelo Fraietta wrote:
> Robert S. Grimes wrote:
>
>   
>> Hi,
>>
>> I'm just looking for some advice and pointers here - no specific 
>> problems (yet!)...
>>
>> What are the relative pros and cons of the various available dynamic 
>> memory allocation approaches in modern RTEMS applications?  One choice 
>> is the C++ operators new/delete, which presumably call malloc and free 
>> under the covers.  What are the characteristics wrt determinism, 
>> fragmentation, etc.?
>>     
>
> It depends on what your requirements are.
>   
Isn't that _always_ true? ;-)  I hesitated to write my email because my 
requirements vary in several instances, so I'm just gathering 
information right now...
> I had to develop a per class allocator due to the number of allocations
> and deallocations I was making. I found that using the heap, my app
> froze after about 2 days running (it was doing 100 allocations and
> deallocations per second) due to memory fragmentation.
> After implementing my allocator for each class, through overloading
> operators new and delete in each class, my app ran two weeks without
> incident with the same number of allocations and deallocations.
>   
This is my concern for one of my needs.  This example of yours is 
relatively similar to one particular instance, except in my case, it's 
probably more like 10 alloc/dealloc per second.  So your approach sounds 
good in this case.  This is the direction in which I was leaning, so to 
hear of a comparable "real-world" case is reassuring!

Might I ask what you based your allocator on?  Did you use a chunk of 
memory from the heap, and manage that yourself?  Or did you use RTEMS 
Regions or Partitions?  I'm particularly interested in the "quality" of 
those subsystems.

Thanks for the feedback!
-Bob
>
>   



More information about the users mailing list