Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itk_alloc.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itk_alloc.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:30 $
00007   Version:   $Revision: 1.4 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef itk_alloc_h
00018 #define itk_alloc_h
00019 
00020 // That is an adaptor for working with any alloc provided below
00021 template<class T, class Alloc>
00022 class itk_simple_alloc {
00023   typedef Alloc alloc_type;
00024 public:
00025   typedef typename Alloc::value_type alloc_value_type; // awf
00026   typedef T value_type;
00027 
00028 #if !__STL_EAGER_TYPECHECK
00029   enum {
00030     chunk = sizeof(value_type)/sizeof(alloc_value_type)+(sizeof(value_type)%sizeof(alloc_value_type)>0)
00031   };
00032 #else
00033   // note: any out-of-line template definitions will not see this.
00034 #define chunk (sizeof(value_type)/sizeof(alloc_value_type)+(sizeof(value_type)%sizeof(alloc_value_type)>0))
00035 #endif
00036 
00037   static value_type *allocate(size_t n)
00038     { return 0 == n? 0 : (value_type*) alloc_type().allocate(n * chunk, 0); }
00039   static value_type *allocate(void)
00040     { return (value_type*) alloc_type().allocate(chunk, 0); }
00041   static void deallocate(value_type *p, size_t n)
00042     { if (0 != n) alloc_type().deallocate(p, n * chunk); }
00043   static void deallocate(value_type *p)
00044     { alloc_type().deallocate((char*)p, chunk); }
00045   
00046 #undef chunk
00047 };
00048 #endif

Generated at Wed May 24 22:44:53 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000