[Bf-committers] multires memory usage

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Dec 19 16:48:02 CET 2006


Hi Nicholas,

While working with the multires code for multi uv, I found switching 
levels to be quite slow. Looking at a time profile, it appears around 
80% of the time is spent in MEM_mallocN/MEM_free. This code does many 
small allocations, and some of these are even preserved in memory after 
switching levels (vert_edge_map and vert_face_map). Small allocations 
are bad because:

- malloc is a slow function (it has to solve a complicated problem, 
packing all those allocations into memory without wasting too much)
- MEM_malloc makes it even slower
- many small allocations can fragment memory,
- MEM_mallocN adds extra overhead to all allocations, 40 bytes per 
allocation.

The solution is to either allocate an array, or if it's hard to know the 
size in advance, use BLI_memarena.

Brecht.



More information about the Bf-committers mailing list