simple.cc - generated code example
[prop.git] / lib-src / memory / blacklistmem.cc
bloba4b27984125439ff7e63878772a6b2d5f684e266
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #include <AD/memory/blacklistmem.h>
26 #include <AD/gc/gcheaps.h>
28 //////////////////////////////////////////////////////////////////////////////
29 // Constructor and destructor
30 //////////////////////////////////////////////////////////////////////////////
31 BlacklistMem:: BlacklistMem(Mem& m) : Mem("BlacklistMem"), mem(m) {}
32 BlacklistMem::~BlacklistMem() {}
34 //////////////////////////////////////////////////////////////////////////////
35 // Error reporting
36 //////////////////////////////////////////////////////////////////////////////
37 void BlacklistMem::error(const char message[]) const { mem.error(message); }
39 //////////////////////////////////////////////////////////////////////////////
40 // Methods for allocation/deallocation
41 //////////////////////////////////////////////////////////////////////////////
42 void * BlacklistMem::m_alloc(size_t n)
43 { void * p = mem.m_alloc(n);
44 HM::blacklist(p,n);
45 return p;
47 void * BlacklistMem::c_alloc(size_t n)
48 { void * p = mem.c_alloc(n);
49 HM::blacklist(p,n);
50 return p;
52 void BlacklistMem::clear() { mem.clear(); }
53 void BlacklistMem::free(void * p)
54 { if (p)
55 { size_t n = mem.size(p);
56 memset(p,0,n);
57 mem.free(p);
58 HM::unblacklist(p,n);
61 size_t BlacklistMem::size(const void * p) const { return mem.size(p); }
62 size_t BlacklistMem::bytes_used() const { return mem.bytes_used(); }
63 size_t BlacklistMem::init_page_size(size_t n) const { return mem.init_page_size(n); }
64 size_t BlacklistMem::max_size(size_t n) const { return mem.max_size(n); }