With snmalloc we can provide a custom meta-data per object that is attached to the standard snmalloc meta-data such as free lists.
|
struct ArrayClientMetaDataProvider |
|
{ |
|
using StorageType = T; |
|
using DataRef = T&; |
|
|
|
static size_t required_count(size_t max_count) |
|
{ |
|
return max_count; |
|
} |
|
|
|
static DataRef get(StorageType* base, size_t index) |
|
{ |
|
return base[index]; |
|
} |
|
}; |
We could use this feature to store a single bit per object. The bit being set means the allocation does not consume the whole allocated space. The last byte then represents how much space is not being used by the allocation, i.e. 17 byte allocation, would have the last byte as 15 (32 - 17) and the bit would be set, whereas a 32 byte allocation would not have the bit set.
With snmalloc we can provide a custom meta-data per object that is attached to the standard snmalloc meta-data such as free lists.
snmalloc/src/snmalloc/backend_helpers/commonconfig.h
Lines 89 to 103 in 012138e
We could use this feature to store a single bit per object. The bit being set means the allocation does not consume the whole allocated space. The last byte then represents how much space is not being used by the allocation, i.e. 17 byte allocation, would have the last byte as 15 (32 - 17) and the bit would be set, whereas a 32 byte allocation would not have the bit set.