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