769 questions
2 votes
1 answer
111 views
Why does my custom global allocator crash on large allocations, and how can I handle alignment properly?
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 ...
0 votes
0 answers
88 views
Is on-demand creation of stateless allocator or deleted allowed by the standard?
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, ...
9 votes
1 answer
169 views
Is it allowed to call `deallocate` on a moved-from allocator (MSVC standard containers do)
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 ...
4 votes
2 answers
211 views
Why doesn't a container (e.g.) vector pass allocator to allocator-aware element-type?
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 ...
4 votes
1 answer
118 views
std::list with a custom allocator crashes when removing items
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 ...
0 votes
0 answers
38 views
C++ uses-allocator construction with allocator aware constructors - inconsistency between std::allocator and std::pmr::polymorphic_allocator
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 ...
5 votes
2 answers
265 views
Can I safely use uintptr_t in my arena allocator?
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 #...
2 votes
1 answer
122 views
C++17 std:map w/allocator gives compile error C2338 (VS 2022)
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&...
0 votes
0 answers
50 views
why std::pmr::unsynchronized_pool_resource does not reuse the memory if there's a weak pointer to the allocated shared pointer?
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 &...
1 vote
0 answers
117 views
What is the difference between the conversion (obj1*)(void*)p and (obj1*)p where p is a pointer to obj2 type
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 ...
4 votes
2 answers
153 views
Given that allocators are copied by value how is allocator state shared?
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 ...
3 votes
0 answers
171 views
Workaround for lack of destroying_delete_t in C++?
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 ...
1 vote
0 answers
75 views
C++: specialization of custom Allocator for use with std::allocate_shared
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 ...
2 votes
1 answer
106 views
Is it possible to have a stack allocator that contains a buffer?
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 ...
6 votes
2 answers
408 views
Do C and C++ differ on the legality of aligning pointers at runtime?
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 ...