forked from Alepha/Alepha
Blob based per-thread slab allocator
This permits "stateless" allocators which grab memory from a `thread_local Alepha::Blob` instance. Each allocation sticks a malloc cookie of type `std::shared_ptr< Alepha::Blob::StorageReservation >` just before the base of the allocation. The allocator object knows that it needs to `reinterpret_cast` the malloc cookie into a shared pointer and run its destructor. This causes the Blob's underlying reference counted allocation to be tied to the lifetime of the allocated memory. The intent is to permit cheap allocation in one thread and deallocation in another. Each deallocation should be a single atomic dereference operation. Each allocation should be (usually) a bit of pointer arithmetic and a single atomic increment operation. This, hopefully, eliminates significant thread contention for the global allocation mechanism between various threads in an intensive multithreaded situation where each processing thread thread may independently retire data objects allocated by a single source.
This commit is contained in:
49
Memory/ThreadSlab.test/0.cc
Normal file
49
Memory/ThreadSlab.test/0.cc
Normal file
@ -0,0 +1,49 @@
|
||||
static_assert( __cplusplus > 2020'99 );
|
||||
|
||||
#include "../ThreadSlab.h"
|
||||
|
||||
#include <Alepha/Testing/test.h>
|
||||
|
||||
#include <Alepha/Utility/evaluation_helpers.h>
|
||||
|
||||
static auto init= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
using namespace Alepha::Testing::literals;
|
||||
|
||||
using namespace Alepha::Memory::exports::ThreadSlab_m;
|
||||
using String= ThreadSlabString;
|
||||
|
||||
|
||||
"Check slab usage"_test <=[]
|
||||
{
|
||||
std::cout << "I see " << Alepha::Memory::ThreadSlab< char >::slab.reservation().use_count() << " reservations in a separate test." <<
|
||||
std::endl;
|
||||
};
|
||||
|
||||
"Can we work with simple `ThreadSlabStrings` without errors?"_test <=[]
|
||||
{
|
||||
String s;
|
||||
std::cerr << "s is empty" << std::endl;
|
||||
|
||||
String s2= "Hello World";
|
||||
std::cerr << "small hello world string." << std::endl;
|
||||
|
||||
String s3= s2 + ": and bob";
|
||||
|
||||
for( int i= 0; i < 10; ++i )
|
||||
{
|
||||
std::cerr << "appended..." << std::endl;
|
||||
s3= s3 + s3 + s2;
|
||||
|
||||
s2= std::move( s3 );
|
||||
}
|
||||
|
||||
std::cout << s3 << std::endl;
|
||||
};
|
||||
|
||||
"Check slab usage"_test <=[]
|
||||
{
|
||||
std::cout << "I see " << Alepha::Memory::ThreadSlab< char >::slab.reservation().use_count() << " reservations in a separate test." <<
|
||||
std::endl;
|
||||
};
|
||||
};
|
||||
1
Memory/ThreadSlab.test/CMakeLists.txt
Normal file
1
Memory/ThreadSlab.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
unit_test( 0 )
|
||||
Reference in New Issue
Block a user