Natural alignment for USE_MALLOC (#248)
* Add concept of natural alignment to tests. snmalloc naturally aligns blocks very heavily, so that the largest power-of-two in the rounded size is the alignment. This checks that in the test, and provides a method for finding the natural alignment of a block. * Improve USE_MALLOC to provide alignment snmalloc provides a lot of alginment guarantees. This ensures that when we pass through to the system allocator we still get those alignment guarantees. The commit also fixes the tests to work with USE_MALLOC, and builds a set of unit tests for ctest to check behaviour.
This commit is contained in:
committed by
GitHub
parent
f89f78ad46
commit
923705e514
@@ -198,4 +198,12 @@ namespace snmalloc
|
||||
}
|
||||
return sizeclass_to_size(size_to_sizeclass(size));
|
||||
}
|
||||
|
||||
/// Returns the alignment that this size naturally has, that is
|
||||
/// all allocations of size `size` will be aligned to the returned value.
|
||||
SNMALLOC_FAST_PATH static size_t natural_alignment(size_t size)
|
||||
{
|
||||
auto rsize = round_size(size);
|
||||
return bits::one_at_bit(bits::ctz(rsize));
|
||||
}
|
||||
} // namespace snmalloc
|
||||
|
||||
Reference in New Issue
Block a user