DavidMorre / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Extension suggestion: aligned allocation #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It will be very useful for many applications if malloc result, casted to an
appropriately sized integer, is guaranteed to be aligned by some predefined
value on request.

Usually it doesn't matter what is the value of the actual pointer.

But consider the situation, when an application massively allocates objects
of the fixed size. So in C++ constructor and destructor operators are
overloaded and fixed sized allocator is implemented. But when the object is
destroyed, it's important to know where the block containing this memory is
located to potentially release it back to malloc or to do some accounting.
If malloc can return aligned by <object_size*num_objects> block, then
simple ptr/N*N or even something like this: ptr&0xfffff000 can be used to
determine the block address. But if malloc returned an arbitrary address,
pointer to the block has to be stored next to the object, effectively
increasing it's size.

So I suggest that new method in class MallocExtension is added:
void* MallocExtension::MallocAligned(size_t size, size_t alignment);

Original issue reported on code.google.com by jerrry94...@yahoo.com on 6 Mar 2010 at 6:29

GoogleCodeExporter commented 9 years ago
I'm not sure I understand.  How is your proposal different from 
posix_memalign()?

Original comment by csilv...@gmail.com on 6 Mar 2010 at 3:21

GoogleCodeExporter commented 9 years ago
Yes, it's the same as posix_memalign.
Sorry, I didn't know about posix_memalign.

Please close this PR.

Original comment by jerrry94...@yahoo.com on 13 Mar 2010 at 7:48

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 16 Mar 2010 at 7:16