-
Notifications
You must be signed in to change notification settings - Fork 0
About Small Object allocator
Memory allocator for C++ small objects. Small object means object with size from 8/16 til 64/128 bytes (32-bit/64-bit).
Allocation method originally described by Andrei Alexandrescu in "Modern C design" book (also know as free list, or pull allocator). Anyway original memory allocator from Loki library is depreciated noways, because it was designed for single core CPU's architecture, as well as it is much slowed comparative to most memory allocators you have in your lib std. Andrei using mutex to synchronize access to the allocator, which brings to performance expensive kernel context switch. Thread synchronization general well known memory allocation algoritms performance bottleneck.
This memory allocator is optimized for multi-core-multithreading apps. Allocator is optimized for random allocation of small object controlled by boost intrusive_ptr an embedded atomic reference counting smart pointer, and can be used when memory allocation speed is important.
You can compare performance of your libc memory allocator and small object allocator with test application bundled.
Allocator is not designed to be used as fast allocator for collections of primitive data like std::vector<int> or std::set<my_struct>, you can use boost pool instead.
Basic usage:
class my_widget: public smallobject::object
{
.....
public:
void resize(uint16_t width, uint16_t height) {
width_ = width;
height_ = height;
}
private:
uint16_t width_;
uint16_t height_;
};
class my_window:public virtual my_widget
{
public:
virtual ~my_window() override
{}
};
DECLARE_OBJECT_PTR_T(my_window);
// or
typedef boost::intrusive_ptr<my_window> s_my_window;
....
s_my_window w(new my_window() );
// or you can use C++ 11 auto etc.
w->resize(640,480);