1 //////////////////////////////////////////////////////////////////////////////
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 welcomed to incorporate any part of ADLib and Prop into
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
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung (leunga@cs.nyu.edu)
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef user_collected_heap_h
26 #define user_collected_heap_h
29 #include <AD/memory/mem.h>
31 //////////////////////////////////////////////////////////////////////////////
32 // Opaque objects (i.e. objects without any pointers)
33 // can be allocated from the class UserHeap using the methods
34 // m_alloc, c_alloc and free.
36 // Class UserHeap gets its memory from the underlying collector, which
37 // is specified during initialization.
38 //////////////////////////////////////////////////////////////////////////////
39 class UserHeap
: public GC
{
41 UserHeap(const UserHeap
&); // no copy constructor
42 void operator = (const UserHeap
&); // no assignment
45 ///////////////////////////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////////////////////////
48 typedef GC::Statistics Statistics
;
49 typedef GC::GCNotify GCNofity
;
52 ///////////////////////////////////////////////////////////////////////////
53 // The underlying garbage collector.
54 ///////////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////////
59 // Constructor and destructor
60 ///////////////////////////////////////////////////////////////////////////
61 UserHeap(); // use GC::default_gc as default
62 UserHeap(GC
&); // use given gc
65 ///////////////////////////////////////////////////////////////////////////
66 // Methods for memory allocation and deallocation.
67 // These should only be used for objects without pointers to
69 ///////////////////////////////////////////////////////////////////////////
70 virtual void * m_alloc (size_t);
71 virtual void * c_alloc (size_t);
72 virtual void free (void *);