Memory allocation size classes

Memory allocators typically allocate only certain sizes, so when you request say 1,000 bytes of memory you will likely be allocated 1,024 bytes, a bit more than requested.

My question is "what are the sizes". I think the answer is "powers of two", at least for small to medium requests, for any allocator you would be likely to be using, but I am not quite sure. Can anyone confirm this is the case?

1 Like

It depends on the memory allocator you use. I know jemalloc has many size classes in-between powers of two for example.

3 Likes

Ah, thanks. I found this:

"All other object size classes are multiples of the quantum, spaced such that there are four size classes for each doubling in size..."

https://jemalloc.net/jemalloc.3.html

Whether that is up-to-date and accurate I don't know.
Edit: given that it is linked directly from https://jemalloc.net/ as the "manual" page, I think it is likely accurate.

BTW, the reason I am asking is in my BTreeMap I need to choose a default allocation scheme. It seems that using 4 steps to double the node allocation would be a reasonable choice.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.