Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a custom memory allocator design pattern that does not store metadata in its allocations? [closed]

Basically, I need a memory pool for fast allocation of small objects. Ideally, I'd like to replace allocations on both the host, and for memory allocated on GPUs with cudaMalloc. I can write my own, and I will if I have to, but I wouldn't mind swapping in one of the solid open-source implementations.

The only issue is that, with cudaMalloc, the memory pool cannot touch the allocated memory. My understanding is that many (all?) of the common memory allocators, like those in the title, store a small amount of metadata in the allocated data. They therefore wouldn't work.

Does anyone know of a memory allocator for which this is not the case?

like image 265
user2333829 Avatar asked Jan 26 '15 15:01

user2333829


1 Answers

If all your small allocations are the same size or have a reasonable upper bound, then a fixed size pool allocator is a good pattern.

The idea is that the allocator grabs a big block using the system call then manages its own free list of fixed size blocks within the big block. Allocation is as easy as taking the block at the head of the free list. Deallocation is a little more complicated but can be implemented in different ways depending on your requirements.

It is simple enough to write your own, or if you google C++ fixed size allocator you can find a number of good implementations including boost::pool

like image 76
Colin Andrews Avatar answered Oct 13 '22 00:10

Colin Andrews