Skip to main content

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
-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....
Srinivasulu 's user avatar
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;...
MaPo's user avatar
  • 683
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> ...
user2961927's user avatar
  • 1,654
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 ...
yqZhang4480's user avatar
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> ...
Stas Furmavnin's user avatar
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-...
blonded04's user avatar
  • 463
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.:...
junglie85's user avatar
  • 1,401
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> ...
Babrorian's user avatar
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 ...
Arne Vogel's user avatar
  • 6,596
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:...
user12694877's user avatar
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]...
Daniel Langr's user avatar
  • 23.1k
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 ...
Torrance's user avatar
  • 450
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 ...
tmlen's user avatar
  • 8,907
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>...
sandthorn's user avatar
  • 2,850
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 ...
metamorphosis's user avatar

15 30 50 per page
1
2 3 4 5
50