Allocator

A component of C++'s Standard Library, in charge of handling the requests for allocation and deallocation of memory for a container.

Boost

Boost is a large collection of high-quality libraries intended for use in C++



Inefficient copying vectors

Example

"Using boost variant is faster than a union and leads imo to the most elegant code;i d guess that the extremely poor performance of the class hierarchy approach is due to the need to use dynamic memory allocator and dynamic dispatch"

from question  

How to return different classes from one function?

"Some people will suggest using std vector s of std vectors but this is inefficient due to the memory allocator and copying that has to occur when the vectors resize;boost has a more efficient version of vectors of vectors in its multi_array lib"

from question  

Multi-dimensional array and pointers in C++?

"The latter doesn t do any dynamic memory allocator and is more than 10 times faster than std to_string on boost karma benchmarks"

from question  

Easiest way to convert int to string in C++

Effect transform_iterator back_inserter

Example

"Boost intrusive_ptr performs better than shared_ptr because it doesn t need a second allocator to hold the reference count"

from question  

C++ Reinforcement learning and smart pointers

"You can almost achieve the desired effect of 1 memory allocator using boost transform_iterator instead of std transform with std back_inserter;the problem though is that because boost transform_iterator cannot return a reference to an element it is tagged as std input_iterator_tag"

from question  

Can STL algorithms and back_inserter preallocate space?

"To be able to use std allocate_shared with boost fast_pool_allocator as the allocator method using g++ 4.8 or higher with boost 1.56.0"

from question  

Boost pool allocators won't compile with std::allocate_shared in g++

Others

Example

Better is to use shared_ptr or many of the other popular smart pointers available in boost and or tr1 and or c++0x;performance-wise objects allocated on the stack can be done so very quickly the stack size is increased per-function-call so all the required memory has been allocated up-front by a simple move of a pointer. contrarily dynamic allocator generally requires much more time

from question  

When to use new in C++?

The problem is that clearly boost icl doesn t currently support stateful allocator;this means that not all constructors take an allocator instance to pass in the required state

from question  

C++ boost icl containers in shared memory

Just to goof off a version using boost string_ref is much faster still due the reduced allocator

from question  

Comparing 3 modern c++ ways to convert integral values to strings

Replacing your containers with boost containers is not a good idea;the work to make appropriate custom allocator wouldn t be that bad but you d be violating the spirit of your allocate at startup rule

from question  

Using boost in embedded system with memory limitation

Boost any internally holds a pointer to an object which it allocates with new;one of the things that makes std vector significantly faster than say std list is that vector keeps all of its objects in a contiguous storage in a single allocator which aside from the obvious reduction in memory allocator overhead is also a lot more cache-friendly

from question  

C++ Performance: template vs boost.any

Back to Home
Data comes from Stack Exchange with CC-BY-SA-4.0