メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

oct-alloc.h

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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   // Get an object from the free list, possibly increasing the size of
00037   // the free list.
00038   void *alloc (size_t size);
00039 
00040   // Put objects back on the free list.
00041   void free (void *p, size_t size);
00042 
00043 private:
00044 
00045   // Structure for internal free list management.
00046   struct link { link *next; };
00047 
00048   // Front of the free list.
00049   link *head;
00050 
00051   // How many objects to get each time we call the global operator new.
00052   int grow_size;
00053 
00054   // The size of each item on the list (or, if that is smaller than
00055   // the size of list*, the size of list*.
00056   size_t item_size;
00057 
00058   // How to grow the free list.
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 ;;; Local Variables: ***
00092 ;;; mode: C++ ***
00093 ;;; End: ***
00094 */

Wed Dec 29 11:52:06 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送