allocator Questions
2
Solved
Let's say I have an allocator my_allocator that will always allocate memory for n+x (instead of n) elements when allocate(n) is called.
Can I savely assume that memory in the range [data()+n, data...
Flivver asked 15/10, 2016 at 2:33
1
Solved
C++17 will bring us std::pmr::memory_resource which is a clean interface for allocating and deallocating memory. Unlike the Allocator concept, it does just that and nothing more. There will also be...
Campanology asked 30/9, 2016 at 19:49
2
Solved
The c++17 specification deprecates the construct and destroy members of the std::allocator object. The working group provided rationale for deprecating other member functions here, under the headin...
Awn asked 9/9, 2016 at 15:5
3
Solved
I've recently been trying to understand how c++ allocators work, and I've been looking to the implementation of the red-black tree that the STL library uses for things like std::set or std::map, bu...
5
Solved
std::allocator is an abstraction over the underlying memory model, which wraps the functionality of calling new and delete. delete doesn't need a size though, but deallocate() requires it.
void...
Pigmy asked 4/8, 2016 at 15:28
1
Solved
While looking at std::allocator, I see that members:
value_type,
pointer,
const_pointer,
reference,
const_reference,
size_type,
difference_type, and
rebind have all been deprecated.
Allocators wi...
Timeserver asked 25/7, 2016 at 10:30
2
Solved
What's the difference between supplying an STL container (for example, std::vector) with an allocator as a template parameter, eg.:
std::vector<int, std::allocator<int>> some_ints;
a...
Burdened asked 14/6, 2016 at 0:26
6
Solved
Will a custom allocator improve performance if many vector<T> s get constructed and destroyed?
In the code below, many vectors with each 10 ints gets constructed with 60% chance or an existing vector gets deleted with 40% chance. Thus, there will be many calls to new/malloc and delete.
Since...
Cauley asked 21/4, 2016 at 8:37
2
Solved
Is there a malloc/free based allocator in the STL? If not, does anyone know of a simple copy/paste one? I need it for a map that must not call new/delete.
2
Solved
8 years ago, Stephen Lavavej published this blog post containing a simple allocator implementation, named the "Mallocator". Since then we've transitioned to the era of C++11 (and soon C++17) ... do...
Purgative asked 9/4, 2016 at 14:3
1
I would like to use a high performance general purpose allocator like jemalloc/tcmalloc with a memory pool. Is there a guide for doing this? I don't want to use jemalloc/tcmalloc as a drop-in repla...
1
As a followup to this question, the default allocator (std::allocator<T>) is required to implement construct as follows (according to [default.allocator]):
template <class U, class... Ar...
Sikh asked 9/3, 2016 at 21:26
1
Solved
std::allocator_traits works its magic automatically when I provide an STL-style container with an allocator that has a single template parameter but it doesn't when I provide an STL-style container...
4
I'm trying to implement a class that's followed in memory by an array of some arbitrary type:
template<class T>
class Buf
{
size_t n;
int refs;
explicit Buf(size_t n) : n(n) { }
// other...
Fiume asked 4/8, 2014 at 0:42
1
Solved
I was trying my hand with allocators this time & felt that there were many chances of leaking the resources. So I thought what if I used std::unique_ptr to handle them. I tried my hand with a s...
Damn asked 21/11, 2015 at 15:29
1
For a software I have to avoid any use of memory in the heap, and only rely on stack-allocated memory. Then, this prevents me from using any C++ standard containers, such as vector, map, string (we...
2
Solved
I'm trying to rebind my custom allocator type, MyAllocator<foo>, for use in a basic_string class, e.g.:
std::basic_string<char, std::char_traits<char>, MyAllocator<char>> ....
1
Solved
Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S, containing a fileds of AllocatorAwareContainer types:
str...
Hachman asked 5/10, 2015 at 9:47
3
I was reading Why is there no reallocation functionality in C++ allocators? and Is it possible to create an array on the heap at run-time, and then allocate more space whenever needed?, which clear...
1
Solved
4
Every allocator class must have an interface similar to the following:
template<class T>
class allocator
{
...
template<class Other>
struct rebind { typedef allocator<Other> ot...
Crafty asked 11/9, 2012 at 3:31
2
Solved
I would like to find a way to store several std::vectors, each of a different but known and reasonably small size, in contiguous memory. I realize I could write my own class, say with a very large ...
4
Solved
I'm building an AVL tree class which will have a fixed maximum number of items. So I thought instead of allocating each item by itself, I'd just allocate the entire chunk at once and use a bitmap t...
Espousal asked 15/4, 2015 at 12:55
1
Solved
The "classic" STL containers such as std::vector and std::map take their allocator types as a template argument. This means that std::vector<T, std::allocator<T>> and std::vector<T, ...
Bethelbethena asked 23/10, 2014 at 3:48
1
Solved
Using a slightly modified version of Howard Hinnants's C++11 stack allocator which is documented here and here, with std::basic_string and compiling with gcc which is using libstdc++, the following...
Pomiculture asked 26/3, 2015 at 17:43
© 2022 - 2024 — McMap. All rights reserved.