Skip to main content
Filter by
Sorted by
Tagged with
-3 votes
0 answers
103 views

I have a solution where I need to write a custom allocator that uses a std::vector as storage for the objects allocated with it. I'm using a std::shared_ptr for the std::vector, and I know that it ...
Georgii Strokov's user avatar
2 votes
1 answer
112 views

I am trying to implement a custom global allocator for use in my Rust application. The goal is to track memory usage and align to 64 bytes. My allocator uses libc::malloc and libc::free for allocation ...
Ronika Kashyap's user avatar
0 votes
0 answers
88 views

Reading what is the new feature in c++20 [[no_unique_address]]? , I have been thinking about alternatives to Empty Base Optimisation prior to C++20's [[no_unique_address]]. One thing came to mind, ...
Dominik Kaszewski's user avatar
9 votes
1 answer
169 views

When MSVC move-constructs an std::set, it also move-constructs the allocator. Later, when it destructs the moved-from set, it uses the allocator to deallocate an element. The following explains what ...
Sven Sandberg's user avatar
4 votes
2 answers
211 views

I've a hard time understanding why a std container doesn't pass on its allocator to its allocator-aware elements. What are the details I miss here? Why isn't the allocator passed on, when - as I ...
kaba's user avatar
  • 547
4 votes
1 answer
118 views

I wrote a memory allocator to use with standard containers. However, every time I try to remove an element from a std::list, the program crashes at the line l.remove(elt). I spent time investigating ...
lilington's user avatar
  • 125
0 votes
0 answers
38 views

When I have an object which has allocator aware constructor, I can easily break the code when switching from std::allocator to std::pmr::polymorphic_allocator. It's beacause the polymorphic_allocator ...
Mi-La's user avatar
  • 735
5 votes
2 answers
269 views

I made a really simple arena allocator in C and I was wondering one thing. Here is my header file (by the way if this api does not seems right please tell me!). #ifndef ARENA_H #define ARENA_H #...
user30097526's user avatar
2 votes
1 answer
124 views

I use std::map with a simple compare function and an allocator. Under C++17 with a map pair of std::pair<type1, type2>, I have learned that the allocator return type is required to be std::pair&...
Ted Ford's user avatar
0 votes
0 answers
50 views

I am playing around with the pmr. I've got this simple code: #include <print> #include <memory_resource> #include <memory> #include <vector> #include <string> #include &...
Shout's user avatar
  • 693
1 vote
0 answers
117 views

Background: I encountered this in GCC c++ standard library extension pool_allocator.h, which contains an allocator type that utilize memory pool to improve the efficiency of small chunk memory ...
Kiyya's user avatar
  • 19
4 votes
2 answers
155 views

I have implemented a custom allocator that takes a block of memory from the stack and allocates linearly out of it, ignoring calls to deallocate. This is used with a std::map to improve performance in ...
Steven's user avatar
  • 720
3 votes
0 answers
171 views

C++20 added the concept of "destroying delete" which lets you create overloads of operator delete that are required to run the object destructor themselves. Normally the destructor call is ...
Joseph Garvin's user avatar
1 vote
0 answers
75 views

I need a custom Allocator to create share_pointer objects ultimately using a pool of dedicated memory. For some classes, however, I will need to further specialize the Allocators. These specialized ...
user28895669's user avatar
2 votes
1 answer
107 views

I'm trying to implement a stack allocator that would work with std::vector. There are plenty of already existing implementations like this or this. However, all of them assume the buffer is not a ...
Smith's user avatar
  • 471
6 votes
2 answers
408 views

Assuming alignment is a uintptr_t power of 2, looking for the next properly aligned address can be done using this expression: (address + alignment - 1u) & ~(alignment - 1u) This is used in ...
MWB's user avatar
  • 12.7k
1 vote
1 answer
53 views

As part of a larger C++11 application, I have a function which creates a Boost JSON object and then returns it. One of the parameters to this function is a Boost JSON storage_ptr to an external ...
Mister Ammaiu's user avatar
0 votes
1 answer
126 views

I am using an external library, and they have a particular convention with their classes that makes no sense to me. They will declare them like this: class SomeClass { public: using ...
jujumbura's user avatar
  • 423
1 vote
2 answers
178 views

C++ standard library containers such as std::vector accept an optional template parameter that lets you specify an alternate allocator. The examples I can find show this happening at each object ...
TaylorE's user avatar
  • 181
2 votes
1 answer
97 views

I'm still learning allocators and I've struggled with the error that occurs, for example, on std::vector::shrink_to_fit() method call. Here is my allocator (I omitted some (I believe) unimportant code ...
qloq's user avatar
  • 1,335
-1 votes
2 answers
106 views

Here is an example of allocator from cppreference: #include <cstdlib> #include <limits> #include <new> template<class T> struct Mallocator { typedef T value_type; ...
qloq's user avatar
  • 1,335
0 votes
0 answers
72 views

I'm learning allocators and I have found that MSVC demand of presence of template constructor for allocator (and g++ and clang do not), here is minimal example of code that triggers error: #include &...
qloq's user avatar
  • 1,335
-1 votes
1 answer
61 views

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
88 views

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
  • 887
1 vote
1 answer
111 views

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,790
7 votes
1 answer
176 views

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
95 views

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
2 votes
2 answers
267 views

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
  • 531
0 votes
1 answer
206 views

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,549
0 votes
1 answer
73 views

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
144 views

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,736
1 vote
2 answers
164 views

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
600 views

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
  • 24.2k
0 votes
0 answers
161 views

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
  • 460
4 votes
1 answer
170 views

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
  • 9,230
2 votes
1 answer
90 views

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,898
0 votes
1 answer
302 views

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
2 votes
1 answer
94 views

I create a map<int, vector<int>> in a Boost Interprocess managed_shared_memory in one process and then want to open it in another process to write to it continually. The other process ...
Moritz Perschke's user avatar
0 votes
0 answers
69 views

As part of a unit test suite for custom std-compatible containers, I want to do some memory tracking. The easiest thing is to define a new allocator and track allocations and deallocations with it, ...
Steven's user avatar
  • 720
2 votes
1 answer
2k views

In Zig, I want specify an allocator at comptime in order to remove the added overhead of passing around an allocator to each function that requires it. In the following MWE, I have a type generator ...
William Ryman's user avatar
0 votes
0 answers
106 views

I have an object of type std::vector<a_trivially_copiable_type, my_custom_allocator>. At some point, I need to inject this into a 3rd-party-library which accepts only a std::vector<...
thebugger's user avatar
  • 235
1 vote
2 answers
372 views

I have read some old posts on propagate_on_container_move_assignment to understand how it works but still not able to wrap my head around some of the finer points. As per my understanding, move ...
DDG's user avatar
  • 171
6 votes
1 answer
127 views

cppreference's example of std::allocator contains this code (shortened for simplicity): // default allocator for ints std::allocator<int> alloc1; using traits_t1 = std::allocator_traits<...
JMC's user avatar
  • 2,123
0 votes
2 answers
875 views

I am trying to use my custom allocator for a std::unordered_map. The allocator already works for my own objects and also for std::vector, but when I try to use it in the same way for a std::...
Jager's user avatar
  • 5
4 votes
1 answer
117 views

After reading a very in-depth article on fancy pointers, where it is also described their correlation with allocators, I had a doubt. The paper covers several aspects of fancy pointers, but does not ...
LoS's user avatar
  • 2,016
0 votes
1 answer
215 views

The monotonic_buffer_resource works a bit like a stack that only supports push but not pop. Unfortunately I see no way howto revert to its previous state when catching an exception. Even when handing ...
Patrick Fromberg's user avatar
0 votes
0 answers
58 views

I have some code that does almost nothing, but it does so in a convoluted way. Most importantly, it does not allocate anything. All data is on the stack. It works just fine with many versions of gcc ...
Patrick Fromberg's user avatar
2 votes
0 answers
42 views

I wondered for a long time how it is possible to assign an allocator of type A to an object expecting an allocator of type B. Check the following code: Demo #include <iostream> #include <...
glades's user avatar
  • 5,374
1 vote
1 answer
631 views

I am looking for solutions to use a memory pool within thrust as I want to limit the number of calls to cudaMalloc. device_vector definitely accepts an allocator, but it's not so easy to deal with ...
brice rebsamen's user avatar
1 vote
1 answer
108 views

I want to create a class Entity that can be templated for owning and non-owning string types (e.g. std::string or std::string_view). In both cases though there is internal datastructure to be ...
glades's user avatar
  • 5,374

1
2 3 4 5
16