Most efficient malloc implementation for many small distributions?

there are tons of small events malloc/ freehigh infant mortality in my application . Normally I would write my own memory pool, but when tcmallocI see usage performance , I am tempted to use the malloc replacement. Are there implementations with similar performance to implement a pool of raw memory packets?

For C ++, I have another application that performs a C ++ new/ dance delete. Suppose children have the same high infant mortality rate. Two questions:

1) How to implement a memory pool that affects operations newand delete?

2) Is there a transparent way, similar to the functions of the glibc malloc dynamic library, to replace the memory allocation block new/ deletefor all classes?

+5
source share
4 answers

Have you considered using force pools? I use this for my base object allocation unit and have no complaint. For ease of use, both safe and unsafe versions are available. There are also many other specialized distributed objects, and you can also consider them.

+1
source

jemalloc. , tcmalloc, , tcmalloc.

0

" ", § 20.6.9 [default.allocator] std::allocator:

#include <new>

// specialize for void:
template <> class allocator<void> {
public:
typedef void* pointer;
typedef const void* const_pointer;
// reference-to-void members are impossible.
typedef void value_type;
template <class U> struct rebind { typedef allocator<U> other; };
};

template <class T> class allocator {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class U> struct rebind { typedef allocator<U> other; };
allocator() throw();
allocator(const allocator&)  throw();
template <class U> allocator(const allocator<U>&)  throw();
~allocator();
pointer address(reference x) const  throw();
const_pointer address(const_reference x) const  throw();
pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
void deallocate(pointer p, size_type n)  throw();
size_type max_size() const  throw();
template<class U, class... Args>
void construct(U* p, Args&&... args);
template <class U>
void destroy(U* p);
};

, -, new delete, .

template<class... Args>
pointer alloc_and_constr(size_type n, Args&&... args);
template <class U>
pointer destr_and_dealloc(U* p);
0

Alexei Alexresrescu std::allocator wrapping: CodeProject

0

All Articles