2#ifndef CLICK_HASHALLOCATOR_HH
3#define CLICK_HASHALLOCATOR_HH
4#if HAVE_VALGRIND && HAVE_VALGRIND_MEMCHECK_H
5# include <valgrind/memcheck.h>
9class HashAllocator {
public:
11 HashAllocator(
size_t size);
14 inline void increase_size(
size_t new_size) {
15 assert(!_free && !_buffer && new_size >= _size);
19 inline void *allocate();
20 inline void deallocate(
void *p);
22 void swap(HashAllocator &x);
26#if HAVE_HASH_ALLOCATOR_POISONING
28 static const uint8_t poison_byte = 0x0d;
42 min_buffer_size = 1024,
44 max_buffer_size = 16384,
46 max_buffer_size = 1048576,
55 void *hard_allocate();
57 HashAllocator(
const HashAllocator &x);
58 HashAllocator &operator=(
const HashAllocator &x);
64class SizedHashAllocator :
public HashAllocator {
public:
67 : HashAllocator(size) {
73inline void *HashAllocator::allocate()
75 if (link *l = _free) {
76#ifdef VALGRIND_MEMPOOL_ALLOC
77 VALGRIND_MEMPOOL_ALLOC(
this, l, _size);
78 VALGRIND_MAKE_MEM_DEFINED(&l->next,
sizeof(l->next));
81#ifdef VALGRIND_MAKE_MEM_DEFINED
82 VALGRIND_MAKE_MEM_UNDEFINED(&l->next,
sizeof(l->next));
85 }
else if (_buffer && _buffer->pos < _buffer->maxpos) {
86 void *data =
reinterpret_cast<char *
>(_buffer) + _buffer->pos;
87 _buffer->pos += _size;
88#ifdef VALGRIND_MEMPOOL_ALLOC
89 VALGRIND_MEMPOOL_ALLOC(
this, data, _size);
93 return hard_allocate();
96inline void HashAllocator::deallocate(
void *p)
99#if HAVE_HASH_ALLOCATOR_POISONING
100 memset(p, poison_byte, _size);
102 reinterpret_cast<link *
>(p)->next = _free;
103 _free =
reinterpret_cast<link *
>(p);
104#ifdef VALGRIND_MEMPOOL_FREE
105 VALGRIND_MEMPOOL_FREE(
this, p);