1
0
forked from Alepha/Alepha

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?
This commit is contained in:
2024-05-12 04:19:33 -04:00
parent d73b4dbe08
commit 172747a435

View File

@ -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