Go to the documentation of this file.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_API
00028 octave_allocator
00029 {
00030 public:
00031
00032 octave_allocator (size_t item_sz, int grow_sz = 256)
00033 : head (0), grow_size (grow_sz),
00034 item_size (item_sz > sizeof (link *) ? item_sz : sizeof (link *))
00035 { }
00036
00037
00038
00039 void *alloc (size_t size);
00040
00041
00042 void free (void *p, size_t size);
00043
00044 private:
00045
00046
00047 struct link { link *next; };
00048
00049
00050 link *head;
00051
00052
00053 int grow_size;
00054
00055
00056
00057 size_t item_size;
00058
00059
00060 bool grow (void);
00061 };
00062
00063 #if defined (HAVE_PLACEMENT_DELETE)
00064 #define DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00065 void operator delete (void *p, void *) \
00066 { ::operator delete (p, static_cast<void*> (0)); }
00067 #else
00068 #define DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00069 void operator delete (void *p, void *) \
00070 { ::operator delete (p); }
00071 #endif
00072
00073 #define DECLARE_OCTAVE_ALLOCATOR \
00074 public: \
00075 void *operator new (size_t size, void *p) \
00076 { return ::operator new (size, p); } \
00077 DECLARE_OCTAVE_ALLOCATOR_PLACEMENT_DELETE \
00078 void *operator new (size_t size) { return allocator.alloc (size); } \
00079 void operator delete (void *p, size_t size) { allocator.free (p, size); } \
00080 private: \
00081 static octave_allocator allocator;
00082
00083 #define DEFINE_OCTAVE_ALLOCATOR(t) \
00084 octave_allocator t::allocator (sizeof (t))
00085
00086 #define DEFINE_OCTAVE_ALLOCATOR2(t, s) \
00087 octave_allocator t::allocator (sizeof (t), s)
00088
00089 #endif