Questions tagged [allocator]
A component of C++'s Standard Library, in charge of handling the requests for allocation and deallocation of memory for a container.
allocator
748
questions
-1
votes
1
answer
41
views
Handle submenu items from a drodown
I want to locate the elements from sub menu
i am trying to locate print but couldn't. how can i fix this?
My code
WebDriver driver = new FirefoxDriver();
driver.get("https://www.flipkart....
1
vote
1
answer
36
views
C++ rebind allocator with two template parameter
I'm writing an allocator that takes alignment as a template parameter also the alignment:
template<typename T, std::align_val_t alignment>
class AlignedAllocator {
public:
using value_type = T;...
1
vote
1
answer
80
views
Unordered_map with customized allocator compiler error
I am new to allocators. I am experimenting with a custom allocator used to allocate std::unordered_map and string:
#include <string>
#include <string_view>
#include <unordered_map>
...
7
votes
1
answer
139
views
What will happen if I call `allocate_at_least(0)` according to C++23 standard?
As shown here, the behavior of allocate(0) is unspecified.
So, what will happen if I call allocate_at_least(0) according to C++23 standard? Is the behavior implementation-defined, or will it be ...
2
votes
0
answers
78
views
How to implement simple allocator for use with STL containers?
I have an allocator, that fine works with std::vector, but has compile errors with std::basic_string. There is my code:
#include <vector>
#include <string>
#include <iostream>
...
1
vote
2
answers
153
views
Why C++ allocators use reinterpret_cast and how to avoid it?
I was trying to implement my own small allocator for testing purposes, and while designing it I thought that I don't know how to implement it without violating strict aliasing rule.
In most open-...
0
votes
1
answer
84
views
Why is a nested allocator in Rust causing heap corruption?
I've been experimenting with the Rust allocator_api feature and have developed a simple linear allocator. My test cases show this works as expected. However, I want to be able to nest allocators, e.g.:...
0
votes
1
answer
54
views
What is the problem when using a custom allocator in c++, when assigning the container to an iterator?
I have the problem that GCC is complaining about a type mismatch when compiling the following code:
#include <iostream>
#include <cstdint>
#include <vector>
#include <limits>
...
6
votes
1
answer
117
views
Why aren't container comparison operators allocator agnostic?
The comparison operators for containers require a matching allocator type, e.g. see the std::vector comparison operators.
That doesn't appear necessary to me… intuitively, all the operator needs to do ...
1
vote
2
answers
100
views
custom allocator and std::map
Here's the code i'm able to compile with gcc:
#include <iostream>
#include <map>
template <class T>
class map_alloc {
public:
typedef std::size_t size_type;
typedef std:...
15
votes
1
answer
560
views
Why std::allocator<T>::allocate calls ::operator new?
The documentation for the std::allocator<T>::allocate member function says in ([allocator.members]) that:
Remarks: The storage for the array is obtained by calling ::operator new ([new.delete]...
0
votes
0
answers
124
views
std::vector not free'ing memory [duplicate]
Under a specific access pattern, I have found a vector of vectors (std::vector<std::vector<Datum>>) might not free all its allocated memory when it is destructed.
For example, in the ...
4
votes
1
answer
107
views
Is std::launder needed after std::uninitialized_default_construct
I have a code similar to the following which uses an allocator to allocate raw memory, and then uses std::uninitialized_default_construct_n (or another function of the same family) to construct ...
2
votes
1
answer
80
views
Why can't I "destroy" CRTP vector that is "self-owned" but still can deallocate its address?
From Björn Fahller's Ligthning Talk at CPP Meeting 2023. => youtu.be/LKKmPAQFNgE
It's about how one can force c++ to leak memory without touching new or even malloc.
struct V : vector<V>...
0
votes
1
answer
143
views
If C++17 and above guarantee that allocators must support overaligned types, does that mean we can avoid creating manually-aligned types?
Given a custom vector and using std::allocator for allocating, under C++17 and above do we still need to create an internal overaligned type OT using alignas, then allocate for OT, and ...