add rust support (#113)
* add rust support * move aligned_size to sizeclass.h * add static qualifier * adjust CMakeLists.txt, may broke CI tests * fix msvc's complaining on c++17 * use SNMALLOC_FAST_PATH as the decorator of aligned_size * adapt new alignment algorithm and add related test Co-authored-by: mjp41 <mattpark@microsoft.com> * fix test cases for msvc * add extra test for size == 0 * treat memory block of same sizeclass as the same * fix formatting problem * remove extra declarations Co-authored-by: Matthew Parkinson <mjp41@users.noreply.github.com>
This commit is contained in:
committed by
Matthew Parkinson
parent
4212ac8e4e
commit
8304dedd17
@@ -174,4 +174,16 @@ namespace snmalloc
|
||||
return relative;
|
||||
}
|
||||
#endif
|
||||
|
||||
SNMALLOC_FAST_PATH static size_t aligned_size(size_t alignment, size_t size)
|
||||
{
|
||||
// Client responsible for checking alignment is not zero
|
||||
assert(alignment != 0);
|
||||
// Client responsible for checking alignment is not above SUPERSLAB_SIZE
|
||||
assert(alignment <= SUPERSLAB_SIZE);
|
||||
// Client responsible for checking alignment is a power of two
|
||||
assert(bits::next_pow2(alignment) == alignment);
|
||||
|
||||
return ((alignment - 1) | (size - 1)) + 1;
|
||||
}
|
||||
} // namespace snmalloc
|
||||
|
||||
Reference in New Issue
Block a user