forked from UNOMP/node-multi-hashing
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathZeroAfterFreeAllocator.h
48 lines (42 loc) · 1.25 KB
/
ZeroAfterFreeAllocator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <memory>
template <typename T>
struct ZeroAfterFreeAllocator : public std::allocator<T>
{
// MSVC8 default copy constructor is broken
typedef std::allocator<T> base;
typedef typename base::size_type size_type;
typedef typename base::difference_type difference_type;
typedef typename base::pointer pointer;
typedef typename base::const_pointer const_pointer;
typedef typename base::reference reference;
typedef typename base::const_reference const_reference;
typedef typename base::value_type value_type;
///@brief constructors and destructor
ZeroAfterFreeAllocator() noexcept
{
}
ZeroAfterFreeAllocator(const ZeroAfterFreeAllocator& a) noexcept
: base(a)
{
}
template <typename U>
ZeroAfterFreeAllocator(const ZeroAfterFreeAllocator<U>& a) noexcept
: base(a)
{
}
~ZeroAfterFreeAllocator() noexcept
{
}
template <typename _Other>
struct rebind
{
typedef ZeroAfterFreeAllocator<_Other> other;
};
void deallocate(T* p, std::size_t n)
{
std::allocator<T>::deallocate(p, n);
}
};
// Byte-vector that clears its contents before deletion.
typedef std::vector<char, ZeroAfterFreeAllocator<char> > CSerializeData;