Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimization of C program with SLAB-like technologies

I have a programming project with highly intensive use of malloc/free functions. It has three types of structures with very high dynamics and big numbers. By this way, malloc and free are heavily used, called thousands of times per second. Can replacement of standard memory allocation by user-space version of SLAB solve this problem? Is there any implementation of such algorithms?

P.S.

  1. System is Linux-oriented.
  2. Sizes of structures is less than 100 bytes.
  3. Finally, I'll prefer to use ready implementation because memory management is really hard topic.
like image 840
Alexander Sannikov Avatar asked Feb 28 '12 16:02

Alexander Sannikov


1 Answers

If you only have three different then you would greatly gain by using a pool allocator (either custom made or something like boost::pool but for C). Doug Lea's binning based malloc would serve as a very good base for a pool allocator (its used in glibc).

However, you also need to take into account other factors, such as multi-threading and memory reusage (will objects be allocated, freed then realloced or just alloced then freed?). from this angle you can check into tcmalloc (which is designed for extreme allocations, both quantity and memory usage), nedmalloc or hoard. all of these allocators are open source and thus can be easily altered to suite the sizes of the objects you allocate.

like image 62
Necrolis Avatar answered Nov 11 '22 20:11

Necrolis