33 #ifndef UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_ 34 #define UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_ 36 #include <stk_util/util/sparseconfig.h> 42 _START_GOOGLE_NAMESPACE_
45 class libc_allocator_with_realloc {
48 typedef size_t size_type;
49 typedef ptrdiff_t difference_type;
52 typedef const T* const_pointer;
54 typedef const T& const_reference;
56 libc_allocator_with_realloc() {}
57 libc_allocator_with_realloc(
const libc_allocator_with_realloc&) {}
58 ~libc_allocator_with_realloc() {}
60 pointer address(reference r)
const {
return &r; }
61 const_pointer address(const_reference r)
const {
return &r; }
63 pointer allocate(size_type n, const_pointer = 0) {
64 return static_cast<pointer
>(malloc(n *
sizeof(value_type)));
66 void deallocate(pointer p, size_type) {
69 pointer reallocate(pointer p, size_type n) {
70 return static_cast<pointer
>(realloc(p, n *
sizeof(value_type)));
73 size_type max_size()
const {
74 return static_cast<size_type
>(-1) /
sizeof(value_type);
77 void construct(pointer p,
const value_type& val) {
78 new(p) value_type(val);
80 void destroy(pointer p) { p->~value_type(); }
83 libc_allocator_with_realloc(
const libc_allocator_with_realloc<U>&) {}
87 typedef libc_allocator_with_realloc<U> other;
93 class libc_allocator_with_realloc<void> {
95 typedef void value_type;
96 typedef size_t size_type;
97 typedef ptrdiff_t difference_type;
98 typedef void* pointer;
99 typedef const void* const_pointer;
103 typedef libc_allocator_with_realloc<U> other;
108 inline bool operator==(
const libc_allocator_with_realloc<T>&,
109 const libc_allocator_with_realloc<T>&) {
114 inline bool operator!=(
const libc_allocator_with_realloc<T>&,
115 const libc_allocator_with_realloc<T>&) {
119 _END_GOOGLE_NAMESPACE_
121 #endif // UTIL_GTL_LIBC_ALLOCATOR_WITH_REALLOC_H_