Large alloc fix (#178)

* Improved malloc style tests

Added comprehensive testing of realloc, and other minor improvements
to reporting errors.

* Fix realloc resizing for large sizeclasses.

The rounding by sizeclass was incorrect for large allocation.  This fixes
that.

* Ensure alloc_size is committed

There is an awkward interaction between alloc_size and
committing only what is requested.  If the user assumes
everything up to alloc_size is available, then we need to
either store the more precise size for alloc_size to return
or commit the whole 2^n range, so that alloc_size stays simple.

This changes to just make the whole range committed.
In the future, we might want to store a more precise size, so
that the allocation can be sized more precisely.

* Reduce size of objects.
This commit is contained in:
Matthew Parkinson
2020-05-07 06:31:37 +01:00
committed by GitHub
parent 79ca9bdd9d
commit c899ee7ab2
6 changed files with 66 additions and 12 deletions

View File

@@ -185,4 +185,13 @@ namespace snmalloc
return ((alignment - 1) | (size - 1)) + 1;
}
SNMALLOC_FAST_PATH static size_t round_size(size_t size)
{
if (size > size_to_sizeclass(NUM_SIZECLASSES - 1))
{
return bits::next_pow2(size);
}
return sizeclass_to_size(size_to_sizeclass(size));
}
} // namespace snmalloc