allocator

Why did std::allocator lose member types/functions in C++17?

﹥>﹥吖頭↗ 提交于 2020-05-11 03:49:06
问题 While looking at std::allocator, I see that members: value_type , pointer , const_pointer , reference , const_reference , size_type , difference_type , and rebind have all been deprecated. Allocators will also no longer have the members: address , max_size , construct , or destroy . Why did this happen? Did it have something to do with polymophic allocators? 回答1: If you look at the relevant isocpp paper you can see that the first set you mention is now thought to be better placed in std:

taking over memory from std::vector

风流意气都作罢 提交于 2020-04-09 08:00:13
问题 I use an external library which operates on large quantities of data. The data is passed in by a raw pointer, plus the length. The library does not claim ownership of the pointer, but invokes a provided callback function (with the same two arguments) when it is done with the data. The data gets prepared conveniently by using std::vector<T> , and I'd rather not give up this convenience. Copying the data is completely out of the question. Thus, I need a way to "take over" the memory buffer

need to write shared memory allocator for c++ std::vector

心已入冬 提交于 2020-01-24 00:22:06
问题 Please help to write c++ allocator for std::vector< nIcon*> class. All examples i find shows just what methods i need to overwrite, not code examples. I need to implement allocator using shared memory on windows (using CreateFileMapping and MapViewOfFile) 回答1: May I suggest you look at the boost interprocess library? It allows you to create allocators using shared memory. I've seen some examples around, I would say just look a bit more. I agree that none of them do a perfect job, thus I won't

using std::unique_ptr with allocators

爱⌒轻易说出口 提交于 2020-01-14 09:42:12
问题 I was trying my hand with allocators this time & felt that there were many chances of leaking the resources. So I thought what if I used std::unique_ptr to handle them. I tried my hand with a std::vector 's allocator. My code goes like this :- // allocator #include <iostream> #include <vector> #include <memory> using namespace std; class X { int x,ID; static int i; public: X() { cout<<"constructing "; ID=++i; cout<<"ID="<<ID<<'\n'; } X(int a) { x=a; cout<<"constructing "; ID=++i; cout<<"ID="<

Standard library facilities which allocate but don't use an Allocator

别等时光非礼了梦想. 提交于 2020-01-10 14:15:15
问题 In most places where the C++ standard library allocates memory, the user is able to customise this by providing a class which meets the Allocator requirements. For example, almost all containers take an allocator template argument, and std::allocate_shared returns a shared_ptr whose contained element and control block are both allocated via a provided Allocator. However, there are a few places where the standard library can (potentially) allocate memory, but no Allocator support is provided.

Replace Standard C++ Allocator?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 15:58:32
问题 I want to replace the standard allocator with a more robust allocator (the C++ standard only requires an overflow check on vector::resize). The various C++ allocators supplied with many libraries fall flat on their face when fed negative self tests. I have access to a more robust allocator. ESAPI's allocator not only checks for overflow, it also has debug instrumentation to help find mistakes. http://code.google.com/p/owasp-esapi-cplusplus/source/browse/trunk/esapi/util/zAllocator.h. Is there

Using custom allocator for AllocatorAwareContainer data members of a class

流过昼夜 提交于 2020-01-03 00:39:12
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

Using custom allocator for AllocatorAwareContainer data members of a class

坚强是说给别人听的谎言 提交于 2020-01-03 00:39:08
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

Requirements on standard library allocator pointer types

99封情书 提交于 2020-01-01 09:02:34
问题 I am trying to write a quadtree sparse matrix class. In short, a quadtree_matrix<T> is either the zero matrix or a quadruple (ne, nw, se, sw) of quadtree_matrix<T> . I'd like eventually to test different allocation schemes since this will probably impact the performance of linear algebra operations. So I will also template quadtree_matrix on a standard allocator type, so that I can reuse existing allocators. I will have to allocate two different kind of data: either a T , or a node , which

C++ STL allocator vs operator new

心不动则不痛 提交于 2019-12-31 08:08:17
问题 According to C++ Primer 4th edition, page 755, there is a note saying: Modern C++ programs ordinarily ought to use the allocator class to allocate memory. It is safer and more flexible. I don't quite understand this statement. So far all the materials I read teach using new to allocate memory in C++. An example of how vector class utilize allocator is shown in the book. However, I cannot think of other scenarios. Can anyone help to clarify this statement? and give me more examples? When should