You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 24, 2020. It is now read-only.
incoder edited this page Mar 14, 2018
·
3 revisions
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:
classmy_widget: publicsmallobject::object
{
.....
public:voidresize(uint16_t width, uint16_t height) {
width_ = width;
height_ = height;
}
private:uint16_t width_;
uint16_t height_;
};
classmy_window:publicvirtual my_widget
{
public:virtual~my_window() override
{}
};
DECLARE_OBJECT_PTR_T(my_window);
// ortypedef 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);