4 ms·
While this was not the point of the comment, one thing missing is that oldsize and newsize should be rounded for alignment purposes: struct my_allocator {
by cataphract 3y ago
While this was not the point of the comment, one thing missing is that oldsize and newsize should be rounded for alignment purposes:
struct my_allocator {
struct hamt_allocator parent;
size_t used;
union {
char buffer[8192];
max_align_t _align;
};
};
static inline size_t align_size(size_t value)
{
size_t alignment = _Alignof(max_align_t);
// if (value % _Alignof(max_align_t) == 0) {
// return value;
// } else {
// return ((value / alignment) + 1) * alignment;
// }
return value + (alignment - 1) & ~(alignment - 1);
}
Even better, the allocator function should get the alignment so don't waste bytes unnecessarily.