This example demonstrates using of custom memory allocators.In this case allocator works as a memory checker, counts number of allocations and deallocations to make sure that there is no memory leaks.
#include <iostream>
#include <cassert>
using namespace std;
{
public:
{
assert(n);
*p = (unsigned)n;
return ++p;
}
{
--p;
::free(p);
}
{
}
};
{
public:
static void*
allocate(
size_t n,
const void *)
{
assert(sizeof(size_t) == sizeof(void*));
void* p = ::malloc((n+1) * sizeof(void*));
size_t* s = (size_t*) p;
*s = n;
return (void*)++s;
}
{
size_t* s = (size_t*) p;
--s;
::free(s);
}
{
}
};
typedef
{
try
{
{
bv[10] = true;
bv[100000] = true;
bv[10000000] = false;
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}
Compressed bit-vector bvector<> container, set algebraic methods, traversal iterators.
pre-processor un-defines to avoid global space pollution (internal)
Bitvector Bit-vector container with runtime compression of bits.
BM style allocator adapter.
static bm::word_t * allocate(size_t n, const void *)
static void deallocate(bm::word_t *p, size_t)
static void * allocate(size_t n, const void *)
static void deallocate(void *p, size_t)
bm::bvector< dbg_alloc > bvect
bm::mem_alloc< dbg_block_allocator, dbg_ptr_allocator, bm::alloc_pool< dbg_block_allocator, dbg_ptr_allocator > > dbg_alloc