Re:So you want custom allocator support in your C library
by saagarjha on Sunday December 17, 2023 @10:01PM
(#38678798)
Most allocators can do this lookup quickly, sometimes by placing the size next to the allocation or by encoding it into the returned pointer.
[ Parent
| on HN ]
Re:So you want custom allocator support in your C library
by lifthrasiir on Sunday December 17, 2023 @10:18PM
(#38678887)
> by encoding it into the returned pointer
More accurately speaking though, this information is not directly available from the pointer (unless we have a universal pointer tagging support today...) and should be mapped via the allocator internal data structure. This is what o11c referred by "arenas/buckets/whatever", and having a size information does simplify this process.
The metadata around the allocation is comparably expensive especially for smaller allocations anyway, so modern allocators would have at least two classes of memory depending on the size. So even when the allocator doesn't make use of any other size information, it is possible that the size information can still be helpful.
Re:So you want custom allocator support in your C library
by jaywee on Monday December 18, 2023 @12:26AM
(#38679516)
It can be - the allocator just needs to mmap() different bucket pools to different base addresses.
Re:So you want custom allocator support in your C library
by saagarjha on Sunday December 17, 2023 @11:40PM
(#38679302)
Having the size is definitely useful, because you can skip the metadata. But since needing this information in some form or the other is very important it is generally easy to derive-no walks or anything, because that would be slow.