The win::process_heap_allocator template is an extension to the set of STL allocators that allocates memory from a process heap.
template <typename T>
class win::process_heap_allocator {
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T * pointer;
typedef const T * const_pointer;
typedef T & reference;
typedef const T & const_reference;
typedef T value_type;
template <typename T2>
struct rebind {
typedef process_heap_allocator <T2> other;
};
public:
process_heap_allocator () throw ();
process_heap_allocator (const process_heap_allocator &) throw ();
template <typename T2>
process_heap_allocator (const process_heap_allocator <T2> &) throw ();
~process_heap_allocator () throw ()
public:
pointer address (reference) const;
const_pointer address (const_reference) const;
pointer allocate (size_type, const void * = 0);
void deallocate (pointer, size_type);
size_type max_size () const throw ();
void construct (pointer, const T &);
void destroy (pointer);
};
template <typename T>
bool win::operator == (const win::process_heap_allocator <T> &,
const win::process_heap_allocator <T> &) throw ();
template <typename T>
bool win::operator != (const win::process_heap_allocator <T> &,
const win::process_heap_allocator <T> &) throw ();
To increase performance, the heap is set to be Low Fragmentation Heap (see MSDN). But this may also increase memory usage for simple applications. To suppress this behavior, define WIN_NO_LOW_FRAGMENTATION_HEAP when compiling the "ext/win_bits/process_heap_allocator.cpp" file to use normal heaps. Moreover, if the project is compiled with _WIN32_WINNT set to 0x0501 or higher, the HeapSetInformation function will be linked statically, thus preventing the application from running on Windows earlier than Windows XP.
All constructors and the destructor are not documented above because they are no-ops; the functions have empty implementation and do nothing.
You will need to include "ext/win_bits/process_heap_allocator.cpp" into your project in order to use win::process_heap_allocator.
#include <ext/win>
#include <vector>
std::vector <int, win::process_heap_allocator> int_heap;
int main () {
int_heap.push_back (1);
int_heap.push_back (2);
int_heap.push_back (3);
int_heap.reserve (10);
// ...
int_heap.clear ();
return 0;
};
A process-heap is a memory heap that is created for every Win32/64 process when started.
The implementation uses the Windows API heap functions thread-safely.
The win::process_heap_allocator design is based on implementations of GCC G++ extended allocators.
[index]