From 172747a4356da8170bfeab890d2802b4eb0ccb26 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 12 May 2024 04:19:33 -0400 Subject: [PATCH] This makes the slab with slots work... But I run out of slots. Always. Because debris of alien allocators gets left behind. Maybe I should go stateless... and the pointer to the memory is _known_ to have a sealed shared_ptr hidden behind it? --- Memory/ThreadSlab.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Memory/ThreadSlab.h b/Memory/ThreadSlab.h index 47be4a2..bc13568 100644 --- a/Memory/ThreadSlab.h +++ b/Memory/ThreadSlab.h @@ -31,11 +31,19 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m using Slot= std::tuple< void *, Blob::StorageReservation >; std::array< Slot, 16 > slots; + void + dumpSlots() const + { + std::cerr << "Slot map for " << (void *) this << std::endl; + for( const auto &[ key, res ]: slots ) + { + std::cerr << (void *) key << " -> " << (void *) res.get() << std::endl; + } + } + std::size_t freeSlots() const { - std::cerr << "Slot map for " << (void *) this << std::endl; - for( const auto &[ key, res ]: return std::count( begin( slots ), end( slots ), Slot{ nullptr, nullptr } ); } @@ -62,6 +70,7 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m allocate( const std::size_t amt ) { std::cerr << "Pre allocation there are " << freeSlots() << " free slots" << std::endl; + dumpSlots(); if( slab.size() < amt ) slab.reset( std::max( amt, C::slabSize ) ); const auto slot= std::find( begin( slots ), end( slots ), Slot{ nullptr, nullptr } ); @@ -70,8 +79,10 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m auto next= slab.carveHead( amt ); const auto rv= &next.template as< T >(); *slot= { rv, next.reservation() }; + std::cerr << "Allocated: " << (void *) rv << std::endl; std::cerr << "Post allocation there are " << freeSlots() << " free slots" << std::endl; + dumpSlots(); return rv; } @@ -80,13 +91,16 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m deallocate( T *const p, const std::size_t /* ignored */ ) noexcept { std::cerr << "Pre deallocation there are " << freeSlots() << " free slots" << std::endl; + dumpSlots(); const auto slot= std::find_if( begin( slots ), end( slots ), [p]( const auto &slot ){ const auto &[ which, _ ]= slot; return which == p; } ); assert( slot != end( slots ) ); *slot= { nullptr, nullptr }; + std::cerr << "Deallocated: " << (void *) p << std::endl; std::cerr << "Post deallocation there are " << freeSlots() << " free slots" << std::endl; + dumpSlots(); } friend constexpr bool