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:
Matthew Parkinson
2020-09-28 10:08:19 +01:00
committed by GitHub
parent f89f78ad46
commit 923705e514
16 changed files with 203 additions and 54 deletions

View File

@@ -20,7 +20,7 @@ void test_alloc_dealloc(size_t count, size_t size, bool write)
for (size_t i = 0; i < ((count * 3) / 2); i++)
{
void* p = alloc->alloc<zero_mem>(size);
SNMALLOC_ASSERT(set.find(p) == set.end());
SNMALLOC_CHECK(set.find(p) == set.end());
if (write)
*(int*)p = 4;
@@ -35,14 +35,14 @@ void test_alloc_dealloc(size_t count, size_t size, bool write)
void* p = *it;
alloc->dealloc(p, size);
set.erase(it);
SNMALLOC_ASSERT(set.find(p) == set.end());
SNMALLOC_CHECK(set.find(p) == set.end());
}
// alloc 1x objects
for (size_t i = 0; i < count; i++)
{
void* p = alloc->alloc<zero_mem>(size);
SNMALLOC_ASSERT(set.find(p) == set.end());
SNMALLOC_CHECK(set.find(p) == set.end());
if (write)
*(int*)p = 4;