Repository navigation
Allocators: tests, alignment and PMR::Object fixes, ObjectPoolResource, PMR::makeOwned - #5
Merged
Merged
Conversation
…d allocation and PMR::Object assignment, added ObjectPoolResource and PMR::makeOwned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tests/CMakeLists.txtand linked only to the test executable, so it sits behindPROJECT_IS_TOP_LEVELlike NanoTest. Projects thatadd_subdirectorythis repo never fetch or link it. The tests use it to check that pool and resource allocations don't touch the global heap, or touch it exactly when expected.Tests/Allocators/forPMR.handMultiPoolAllocator.h:DynamicMemory,ResourceContainer,MemoryPool,MemoryPoolResource,PMR::Object/PMR::Vector,makeSharedandmakeOwned.MemoryPoolResourceignored the requested alignment. The alignment now goes throughMemoryPoolandDynamicMemory, which reservebytes + alignment - 1and align withstd::align. The cutoff is__STDCPP_DEFAULT_NEW_ALIGNMENT__, the alignment the block storage already gets fromoperator new, so requests at or below it behave exactly as before.PMR::Objectassignment. Copy and move assignment now keep the target's own resource and assign only the contents, asstd::pmrcontainers do, sogetResource()always matches the resource the wrapped object allocates from.PMR::Objectalso gets a real move constructor, which doesn't allocate.MemoryPoolResourceused to default to 1000 pre-filled 1 MB blocks (about 1 GB at construction). It now defaults to 16 blocks of 64 KB with 1024 reserved bookkeeping slots (about 1 MB).MemoryPool's default counts changed to match (16 / 1024). Existing code that relied on the larger defaults will fall back to the heap sooner.ObjectPoolResource<T>. A pool resource with blocks ofsizeof(T)that honoursalignof(T), pre-filled with N blocks (default 1024).PMR::makeOwned<T>(resource, args...)returnsPMR::Owned<T>, astd::unique_ptrwhose deleter frees the memory back to the same resource with the size and alignment captured at creation. Converting toOwned<Base>is allowed only whenBasehas a virtual destructor.MemoryPooland the pool resources now say they are heap-backed and that pointers stay put until deallocated.Testing
ctest: 563/563 passed locally on macOS (Apple clang). That is the existing tests plus 53 new ones.