allocator Questions

2

Solved

In this context T is a certain type and allocator is an allocator object for that type. By default it is std::allocator<T> but this is not necessarily true. I have a chunk of memory acquired...
Igorot asked 18/5, 2011 at 16:18

1

Class templates in the ::std namespace can generally be specialized by programs for user-defined types. I did not find any exception to this rule for std::allocator. So, am I allowed to specialize...
Retrospect asked 11/4, 2020 at 1:57

3

Solved

I'm trying to implement custom allocator for storing memory mapped files in the std::vector. Files mapping performed by boost::iostreams::mapped_file Allocator type for file memory mapping: templ...
Beastings asked 23/7, 2014 at 2:59

3

Solved

I like to know how things work and as such have been delving deep into the c++ standard library. Something occurred to me the other day. It is required that containters (for example: std::vector&l...
Urion asked 15/3, 2012 at 20:21

2

I know std::array is completely allocated in the stack, but this question is motivated by security concerns that require two things: The data in std::array will be zerod or randomized on destruct...
Gardening asked 7/12, 2019 at 12:11

5

Solved

I found myself in a situation where I would have liked to have an analog of unique_ptr's release() for std::vector<>. E.g.: std::vector<int> v(SOME_SIZE); //.. performing operations o...
Telegraphic asked 9/11, 2016 at 19:14

2

Solved

I would like to customize std::vector behavior to not default-construct the element type (e.g. int), as it is expensive to do this for a large vector. Looking at this, the only way I can see to do...
Stricklin asked 22/11, 2019 at 0:9

3

Say I have a shared_ptr with a custom allocator and a custom deleter. I can't find anything in the standard that talks about where the deleter should be stored: it doesn't say that the custom allo...
Neisa asked 19/11, 2019 at 11:25

3

Solved

This is the code I am using to test this: #include <iostream> #include <boost/interprocess/managed_mapped_file.hpp> #include <boost/container/map.hpp> #include <boost/interpro...
Instead asked 31/10, 2019 at 16:5

1

Solved

As I know std::allocator<T>::construct takes only two parameters on older version of C++; the first is a pointer to raw, un-constructed memory in which we want to construct an object of type ...
Cinthiacintron asked 7/11, 2019 at 12:58

6

Solved

I was wondering if it practicable to have an C++ standard library compliant allocator that uses a (fixed sized) buffer that lives on the stack. Somehow, it seems this question has not been ask thi...
Maddy asked 8/11, 2011 at 11:26

0

I would like to implemented a custom allocator for node-based containers like std::unordered_map or std::list. For that allocator I need to specify the size of the nodes. How do I get this? I know ...
Goodkin asked 12/9, 2019 at 16:19

3

Solved

I use an external library which operates on large quantities of data. The data is passed in by a raw pointer, plus the length. The library does not claim ownership of the pointer, but invokes a pro...
Transit asked 26/11, 2014 at 23:59

1

Solved

I am trying to use Howard Hinnant's stack_alloc with boost rtrees, as in the following example: #include "stack_alloc.h" #include <boost/geometry/index/rtree.hpp> using NodePoint = boost::g...
Scurlock asked 6/8, 2019 at 4:6

7

Solved

I'm new to C++ and I'm using the vector class on my project. I found it quite useful because I can have an array that automatically reallocates whenever it is necessary (ie, if I want to push_back ...
Evangel asked 25/6, 2013 at 14:24

1

Solved

The C++17 Standard says: [mem.poly.allocator.ctor] polymorphic_allocator(memory_resource* r); Requires: r is non-null. Effects: Sets memory_­rsrc to r. Throws: Nothing. [ Note: This co...
Petie asked 6/5, 2019 at 23:12

3

Solved

I profiled my program, and found that changing from standard allocator to a custom one-frame allocator can remove my biggest bottleneck. Here is a dummy snippet (coliru link):- class Allocator{ /...
Quotable asked 1/4, 2019 at 7:18

3

Solved

Here is the documentation on cppreference, here is the working draft. I must admit that I didn't understand what's the real purpose of polymorphic_allocator and when/why/how I should use it. As an...
Bagpipe asked 24/6, 2016 at 9:54

2

Solved

What is the reason for having these traits in a container (https://en.cppreference.com/w/cpp/memory/allocator_traits) propagate_on_container_copy_assignment Alloc::propagate_on_container_copy_assig...

0

There are many classes in the standard c++ library which potentially allocate memory but do not accept an allocator. Some of them do so because allocating memory in a type-erased context is not pos...
Amylaceous asked 14/2, 2019 at 18:55

1

Solved

I have a vector<vector<int>> and want the entire memory (i.e., of both the outer and the inner vector) to be taken from a memory_resource. Here is a stripped down example, first the bor...
Undeceive asked 12/2, 2019 at 16:29

1

Solved

I am implementing an allocator for std::map and std::set in C++14. The allocator has to provide a function pointer allocate(size_type n) that allocates space for n items at a time. After some test...
Lil asked 18/1, 2019 at 11:43

2

Related: Why do standard containers require allocator_type::value_type to be the element type? It is said that the following has been deprecated since C++17: template<> struct allocator<...
Pinard asked 9/5, 2018 at 2:42

2

Solved

Before c++17, if you have an allocator like Allocator<typename, size_t> you can use the rebind struct. But now, in C++17 the rebind struct is deprecated. What's the solution to construct an a...
Artificial asked 8/1, 2019 at 12:59

3

Solved

I want to create a non-copyable allocator (in C++14) which just allocates a fixed memory block a std::vector can use. I want to prevent the allocator (and therefore also the vector) from being copy...
Nilson asked 4/12, 2018 at 16:11

© 2022 - 2024 — McMap. All rights reserved.