00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_oct_alloc_h)
00024 #define octave_oct_alloc_h 1
00025
00026 class
00027 octave_allocator
00028 {
00029 public:
00030
00031 octave_allocator (size_t item_sz, int grow_sz = 256)
00032 : head (0), grow_size (grow_sz),
00033 item_size (item_sz > sizeof (link *) ? item_sz : sizeof (link *))
00034 { }
00035
00036
00037
00038 void *alloc (size_t size);
00039
00040
00041 void free (void *p, size_t size);
00042
00043 private:
00044
00045
00046 struct link { link *next; };
00047
00048
00049 link *head;
00050
00051
00052 int grow_size;
00053
00054
00055
00056 size_t item_size;
00057
00058
00059 bool grow (void);
00060 };
00061
00062 #if defined (HAVE_PLACEMENT_DELETE)
00063 #define DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00064 void operator delete (void *p, void *) \
00065 { ::operator delete (p, static_cast<void*> (0)); }
00066 #else
00067 #define DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00068 void operator delete (void *p, void *) \
00069 { ::operator delete (p); }
00070 #endif
00071
00072 #define DECLARE_OCTAVE_ALLOCATOR \
00073 public: \
00074 void *operator new (size_t size, void *p) \
00075 { return ::operator new (size, p); } \
00076 DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00077 void *operator new (size_t size) { return allocator.alloc (size); } \
00078 void operator delete (void *p, size_t size) { allocator.free (p, size); } \
00079 private: \
00080 static octave_allocator allocator;
00081
00082 #define DEFINE_OCTAVE_ALLOCATOR(t) \
00083 octave_allocator t::allocator (sizeof (t))
00084
00085 #define DEFINE_OCTAVE_ALLOCATOR2(t, s) \
00086 octave_allocator t::allocator (sizeof (t), s)
00087
00088 #endif
00089
00090
00091
00092
00093
00094