allocator

std::list in a boost::interprocess::managed_shared_memory

六眼飞鱼酱① 提交于 2019-12-11 13:06:47
问题 Recently I got schooled and learnt the proper way of having a unordered_map inside a boost::interprocess::managed_shared_memory segment. So far so good, but I will need to add a few more STL containers. Ideally, I would want to be able to follow the same for any STL container. Right now I'm in need of a std::list. I can't make it work. I can make a std::vector work, though. std::vector The following code works: #include <vector> #include <boost/interprocess/managed_shared_memory.hpp>

Allocator-aware `std::array`-style container?

别等时光非礼了梦想. 提交于 2019-12-11 07:31:43
问题 I'm writing some code that handles cryptographic secrets, and I've created a custom ZeroedMemory implementation of std::pmr::memory_resource which handles sanitizes memory on deallocation and encapsulates using the magic you have to use to prevent optimizing compilers from eliding away the operation. The idea was to avoid specializing std::array , because the lack of a virtual destructor means that destruction after type erasure would cause memory to be freed without being sanitized.

Is it possible to replace the memory allocator in a debug build of an MFC application?

北慕城南 提交于 2019-12-11 07:24:45
问题 I'd like to make use of Electric Fence in an MFC application. I'd like to track new / delete , and if I can track malloc / free that's an added bonus. Unfortunately, MFC redefines new and delete - but using macros (DEBUG_NEW) - so I can't use the standard C++ method of redefining them. (MFC defines them to have different signatures, with source file and line numbers as additional parameters). Is there any way to force all new / delete s to go via my allocator, and stop MFC trying to grab

Custom allocator for fast std::wstring allocations

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:32:42
问题 Is there any open-source allocator (possibly in Boost) that can be used with std::wstring implementing a fast allocation pattern like the one showed in this blog post? Boost.Pool doesn't seem well suited for this purpose. 回答1: No, there isn't (I searched for a couple of hours, once). If you don't care to release memory during usage, it is fairly simple to do yourself. If you want to release it dynamically, then it becomes a lot of work regarding free list management, LRU, etc. 来源: https:/

How does std::list allocate nodes vs. elements

折月煮酒 提交于 2019-12-10 03:21:26
问题 How does std::list allocate the nodes in which it keeps the next / prev pointers and the T element it contains? I think that standard allocators can only be used to allocate memory for one type (because std::allocator::allocate allocates memory in increments of sizeof(T) ). So it seems impossible to allocate the list node and the contained object in a single allocation, which means that the nodes have to be allocated with whatever the implementation decides, and the nodes store pointers to

Type-erased allocators in modern C++

时光怂恿深爱的人放手 提交于 2019-12-10 03:19:09
问题 The "classic" STL containers such as std::vector and std::map take their allocator types as a template argument. This means that std::vector<T, std::allocator<T>> and std::vector<T, MyAllocator> for example are considered completely separate types. Some newer allocator-aware classes like std::shared_ptr and std::tuple on the other hand use type-erasure to "hide" information about the allocator, so it does not form part of the type signature. However, std::unordered_map (which is of a similar

Contiguous memory allocation for several small std::vectors?

柔情痞子 提交于 2019-12-10 03:14:19
问题 I would like to find a way to store several std::vectors , each of a different but known and reasonably small size, in contiguous memory. I realize I could write my own class, say with a very large array and with pointers to the start of each subsection of the array within the larger array treated like a separate entity, but it seems like there should be a smarter way to do this. Is there a way to use allocators , for example, to create contiguous std::vectors ? I'd like not to reinvent the

compiler support for stateful allocators in STL containers

為{幸葍}努か 提交于 2019-12-10 01:42:54
问题 The new C++11 standard requires STL implementations to support stateful allocators in containers. Do main STL implementations (Visual Studio 2008, 2010, libstdc++) comply to this requirement now? I found nothing about this in MSDN or in libstdc++ documentation. 回答1: Looks like the feature of stateful allocators in STL containers is widely supported already. In most cases statefullness of the allocator does not cause trouble. What is not widely supported yet is the new standard's way of

Is Stephen Lavavej's Mallocator the same in C++11?

让人想犯罪 __ 提交于 2019-12-09 05:27:49
问题 8 years ago, Stephen Lavavej published this blog post containing a simple allocator implementation, named the "Mallocator". Since then we've transitioned to the era of C++11 (and soon C++17) ... does the new language features and rules affect the Mallocator at all, or is it still relevant as is? 回答1: STL himself has an answer to this question in his STL Features and Implementation techniques talk at CppCon 2014 (Starting at 26'30). The slides are on github. I merged the content of slides 28

Is there a BOOST pool fixed-sized allocator?

空扰寡人 提交于 2019-12-08 20:59:02
问题 I want to create unordered_map (Because I specifically want a hash map). I want to allocate its max size (according to my constraints) in the beginning. So, if I want to allocated 256 entries, and the size of each entry is 1B (just an example. Let's say 1Byte includes the Key and the Value). Then the total size of my unordered_map keys + entries is 256B. I want to pre-allocate 256B in the allocator. Then, when the unordered_map will call allocate() / deallocate() , the allocator will give it