Category : allocator

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 ..

Read more

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 ..

Read more

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 ..

Read more

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 ..

Read more

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()) ..

Read more

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 ..

Read more