initial
[prop.git] / include / AD / memory / freelist.h
blob114fd8129a2cd636ca8c7e602da5f753c0ff79b2
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 #ifndef free_lists_h
26 #define free_lists_h
28 //////////////////////////////////////////////////////////////////////////////
29 // This trick is borrowed from the LEDA library.
30 //////////////////////////////////////////////////////////////////////////////
32 #include <new.h>
34 #define Max_free_list_cell_size 1023 // we keep free lists up to 1023 bytes.
36 struct Free_list_cell { Free_list_cell * next; };
37 extern Free_list_cell * free_lists[];
39 #define Use_free_list_manager(type) \
40 void * operator new (int) \
41 { Free_list_cell * cell = free_lists[sizeof(type)]; \
42 if (cell) { free_lists[sizeof(type)] = cell->next; return cell; } \
43 else return ::new char [sizeof(type)]; \
44 } \
45 void operator delete(void * t) \
46 { Free_list_cell * cell = (Free_list_cell*)t; \
47 cell->next = free_lists[sizeof(type)]; \
48 free_lists[sizeof(type)] = cell; \
49 } \
51 #define Implement_free_list_manager(max_size) \
52 Free_list_cell * free_lists[max_size];
54 #endif