allocator Questions

2

new int[0] is permitted in C++ but is std::allocator<int>().allocate(0) well defined? More general, must all Allocators accept 0 as a parameter to allocate? Edit: After reading the answers I...

1

Solved

I am using Howard Hinnant's nice little arena-based allocator, short_alloc. It struck me that move-assigning from a vector, which has outgrown its arena and is thus allocated on heap, could be don...
Counselor asked 7/10, 2013 at 16:46

2

Solved

My question here is basically a follow up to : How can I write a stateful allocator in C++11, given requirements on copy construction? Basically, despite the fact that the C++11 standard now allo...
Marie asked 14/12, 2014 at 16:59

1

Solved

The standard C++17 include a new namespace pmr including a set of classes grouped under the name of memory_resource. After a search on internet, I found very few vulgarized information about it, t...
Handal asked 28/6, 2017 at 9:58

1

As far as I understand, std::scoped_allocator_adapter provides a control mechanism for specifying separately which allocator will be used by a container, by its elements, by elements of their eleme...
Furcula asked 21/2, 2017 at 10:27

1

Solved

The Allocator concept and std::allocator_traits do not say what allocate will do when allocation fail -- will it returns nullptr or throw? When I'm writing a container using standard allocator API...
Menticide asked 14/5, 2018 at 9:0

1

Related: Deprecation of std::allocator<void>. The following description about template parameter Allocator is found for both std::vector and std::list (emphasis mine): An allocator that i...
Morton asked 9/5, 2018 at 3:53

1

I am new to boost and I want to know how exactly the boost::pool libraries can help me in creating a custom memory allocator. And I have two vector of struct objects. First vector is of structure t...
Endurance asked 14/2, 2018 at 8:13

2

Solved

I've got an extremely basic allocator: template<typename T> struct Allocator : public std::allocator<T> { inline typename std::allocator<T>::pointer allocate(typename std::alloc...
Brabant asked 9/6, 2011 at 16:33

1

C++ allows dynamic allocation of zero-sized arrays: int* p = new int[0]; delete[] p; I can't do much with such a pointer (as the array has no elements), but the new expression is required to giv...
Auld asked 16/12, 2017 at 8:53

3

Solved

While implementing custom C++ allocator, one needs to define: operator== for the allocator with different value_type operator!= for the allocator with different value_type You can see the examp...
Tendency asked 8/11, 2017 at 18:1

1

Solved

C++17 introduces std::aligned_alloc and alignment-aware new that can do over-aligned allocations, but what about std::allocator? Does it handle over-aligned types?
Renter asked 25/9, 2017 at 7:16

4

Solved

It is said here that it's because of exception specification. I do not understand it. Does this question have any relationship with exception specification?
Giannagianni asked 21/8, 2011 at 8:31

1

Solved

I'm working on a segment-based memory allocator for C++. In this allocator, when you deallocate a chunk of memory, you have to know which segment it came from. Therefore, I'm storing a pointer to t...
Tawnytawnya asked 16/7, 2017 at 19:28

1

From http://en.cppreference.com/w/cpp/memory/polymorphic_allocator: polymorphic_allocator does not propagate on container copy assignment, move assignment, or swap. As a result, move assignment ...
Mcclenon asked 13/7, 2017 at 18:10

1

Solved

Here is a memory layout within a custom allocator :- ^ toward less address .... Header [size=16 alignment=4 ] ....(1) some waste space A [size=A (unknown) ] content [size="SIZE" alignment="ALIGN"]...
Bruise asked 9/7, 2017 at 8:2

1

Solved

I am working with an external library (pcl) so I need a solution that does not change the existing function prototypes. One function that I am using generates an std::vector<int, Eigen::aligned...
Templia asked 6/7, 2017 at 15:23

2

Solved

It seems that the C++ STL container requirements are that the provided allocator type's value_type be the same as the STL container's value_type Requires:allocator_- type::value_type is the same a...
Utah asked 22/5, 2017 at 4:30

1

Solved

I'm writing an allocator with a reference to another instance of some class which tracks the number of allocated bytes. below is a minimal example of what I'm trying to do (adapted from here), jus...
Bulbil asked 5/4, 2017 at 14:22

1

Solved

During my daily work, I am always advised by senior member of the team that list is not cache friendly so I should vector. I understand that list is not continuous so that the memory allocation is ...
Euripides asked 29/3, 2017 at 21:15

1

Solved

In most places where the C++ standard library allocates memory, the user is able to customise this by providing a class which meets the Allocator requirements. For example, almost all containers ta...
Gummosis asked 27/3, 2017 at 20:55

1

Solved

Is it technically valid to use mismatched std::allocator specialization (surely, except its specialization for void) as a template parameter for STL containers (not all of them, but enumerated belo...
Bondstone asked 11/3, 2017 at 14:1

2

Solved

For example, from std::deque::operator = in C++ Reference: (1) Copy Assignment (const std::deque &other) Replaces the contents with a copy of the contents of other. If std::allocator_traits...
Franek asked 25/11, 2016 at 9:34

1

Solved

Is it possible to customize the reference of a std::vector. Until C++11 it seemed to be possible through the Allocator template parameter. But not anymore? According to the documentation, http:/...
Tremolite asked 10/1, 2017 at 23:52

1

Solved

From what I read in http://en.cppreference.com/w/cpp/memory/allocator , most features of the allocators are now going to be deprecated. The question is, how is one supposed to use allocators in new...
Powys asked 18/12, 2016 at 23:14

© 2022 - 2024 — McMap. All rights reserved.