I have a std::map<std::string,std::size_t> of keys mapping counters. When I increment a counter, I don’t know if it already exists. If yes, it is incremented. If not, it is set to 1. This is easy to do: std::map<std::string,std::size_t> counters; //… auto c_it = counters.find(key); if(c_it == counters.end()) counters.insert(key,1); else (*c_it)++; This is a lot of ..
Category : allocator
Is it possible to specialize the std::allocator_traits, template like this? namespace falloc_ { template<class Tp> class FAllocator ; } // partial spec for all falloc_::FAllocator<U>, std::allocator_traits template<typename Tp> struct std::allocator_traits<falloc_::FAllocator<Tp> > { using allocator_type = falloc_::FAllocator<Tp> ; using value_type = typename allocator_type::value_type ; // … // All the components I need here, I will include ..
When allocator’s propagation policy tells to propagate the allocator, on container copy/move assignment or swap, do the container needs to do it even when allocators involved are equal? Source: Windows Que..
I am working on custom allocators. So far, I have tried to work on simple containers: std::list, std::vector, std::basic_string, etc… My custom allocator is a static buffer allocator, its implementation is straightforward: #include <memory> template <typename T> class StaticBufferAlloc : std::allocator<T> { private: T *memory_ptr; std::size_t memory_size; public: typedef std::size_t size_type; typedef T *pointer; typedef ..
I’m using Boost.Interprocess shared memory, and I’m using interprocess Allocator with some STL compatible containers, when it comes to placement new, the code won’t compile since placement new expect void * while boost::interprocess::allocator::pointer can’t not be converted to void *. below is a code to reproduce this #include <memory> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/managed_shared_memory.hpp> namespace ipc ..
I’d like to use a std::vector which allocates the memory for its element from a preallocated buffer. So, I would like to provide a buffer pointer T* buffer of size n to std::vector. I thought I could simply write a std::span-like class which also provides a push_back method; that would be exactly what I need. ..
I have 2 code snippets: 1: std::map<std::string , SerializableBase* , std::less<std::string> , custom_allocator<std::pair<const std::string, SerializableBase*> > > m_membersMap; Anotethere one is 2: std::map<const char* , EventBase* , cmpByStringLength , custom_allocator<std::pair<<const char*, EventBase*>> > m_events; And custom allocaotr impl: template <class T> struct custom_allocator { typedef T value_type; MemBlockBase* m_memBlock = 0; custom_allocator(MemBlockBase* memBlock = StdAllocatorMemBlock::GetMemBlock()) ..
I’m trying to implement my own allocator, which should work with STL containers and use a custom fancy pointer implementation. I’m pretty sure, that my classes fulfill all requirements (according to cppreference) but my implementation doesn’t compile for std::list because there is no conversion from my fancy pointer to a normal pointer. A minimal example ..
Several sources ([1],[2]) mention that the purpose of std::allocator was to allow for different pointer types (near/far/huge) on 16 bit platforms and parts of this original design still remain in the standard. My questions are: How specifically did allocators work with different pointer types those days? For example, if near pointer is meaningless without a ..
Good evening. I noticed that std::vector has some requirements regarding copy and move assignment operator. I’m trying to implement them using (std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value. So my questions: What is it/How does it work? Does Allocator have to be the current allocator, or other‘s Allocator? To implement std::vector move assignment, I have to check 3 conditions: One is ..
Recent Comments