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:
@ -31,11 +31,19 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m
|
|||||||
using Slot= std::tuple< void *, Blob::StorageReservation >;
|
using Slot= std::tuple< void *, Blob::StorageReservation >;
|
||||||
std::array< Slot, 16 > slots;
|
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
|
std::size_t
|
||||||
freeSlots() const
|
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 } );
|
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 )
|
allocate( const std::size_t amt )
|
||||||
{
|
{
|
||||||
std::cerr << "Pre allocation there are " << freeSlots() << " free slots" << std::endl;
|
std::cerr << "Pre allocation there are " << freeSlots() << " free slots" << std::endl;
|
||||||
|
dumpSlots();
|
||||||
if( slab.size() < amt ) slab.reset( std::max( amt, C::slabSize ) );
|
if( slab.size() < amt ) slab.reset( std::max( amt, C::slabSize ) );
|
||||||
|
|
||||||
const auto slot= std::find( begin( slots ), end( slots ), Slot{ nullptr, nullptr } );
|
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 );
|
auto next= slab.carveHead( amt );
|
||||||
const auto rv= &next.template as< T >();
|
const auto rv= &next.template as< T >();
|
||||||
*slot= { rv, next.reservation() };
|
*slot= { rv, next.reservation() };
|
||||||
|
std::cerr << "Allocated: " << (void *) rv << std::endl;
|
||||||
|
|
||||||
std::cerr << "Post allocation there are " << freeSlots() << " free slots" << std::endl;
|
std::cerr << "Post allocation there are " << freeSlots() << " free slots" << std::endl;
|
||||||
|
dumpSlots();
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -80,13 +91,16 @@ namespace Alepha::Hydrogen::Memory ::detail:: ThreadSlab_m
|
|||||||
deallocate( T *const p, const std::size_t /* ignored */ ) noexcept
|
deallocate( T *const p, const std::size_t /* ignored */ ) noexcept
|
||||||
{
|
{
|
||||||
std::cerr << "Pre deallocation there are " << freeSlots() << " free slots" << std::endl;
|
std::cerr << "Pre deallocation there are " << freeSlots() << " free slots" << std::endl;
|
||||||
|
dumpSlots();
|
||||||
const auto slot= std::find_if( begin( slots ), end( slots ),
|
const auto slot= std::find_if( begin( slots ), end( slots ),
|
||||||
[p]( const auto &slot ){ const auto &[ which, _ ]= slot; return which == p; } );
|
[p]( const auto &slot ){ const auto &[ which, _ ]= slot; return which == p; } );
|
||||||
assert( slot != end( slots ) );
|
assert( slot != end( slots ) );
|
||||||
|
|
||||||
*slot= { nullptr, nullptr };
|
*slot= { nullptr, nullptr };
|
||||||
|
std::cerr << "Deallocated: " << (void *) p << std::endl;
|
||||||
|
|
||||||
std::cerr << "Post deallocation there are " << freeSlots() << " free slots" << std::endl;
|
std::cerr << "Post deallocation there are " << freeSlots() << " free slots" << std::endl;
|
||||||
|
dumpSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
friend constexpr bool
|
friend constexpr bool
|
||||||
|
|||||||
Reference in New Issue
Block a user