KWStyle - itk_alloc.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itk_alloc.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:46 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 NMS =========================================================================*/
17 DEF #ifndef itk_alloc_h
18 DEF #define itk_alloc_h
19
20 // That is an adaptor for working with any alloc provided below
21 template<class T, class Alloc>
22 class itk_simple_alloc {
23 TDR   typedef Alloc alloc_type;
24 public:
25 TDR   typedef typename Alloc::value_type alloc_value_type; // awf
26 TDA,TDR   typedef T value_type;
27
28 #if !__STL_EAGER_TYPECHECK
29   enum {
30 LEN     chunk = sizeof(value_type)/sizeof(alloc_value_type)+(sizeof(value_type)%sizeof(alloc_value_type)>0)
31 IND **};
32 IND #else
33   // note: any out-of-line template definitions will not see this.
34 LEN #define chunk (sizeof(value_type)/sizeof(alloc_value_type)+(sizeof(value_type)%sizeof(alloc_value_type)>0))
35 #endif
36
37   static value_type *allocate(size_t n)
38     { return 0 == n? 0 : (value_type*) alloc_type().allocate(n * chunk, 0); }
39   static value_type *allocate(void)
40     { return (value_type*) alloc_type().allocate(chunk, 0); }
41   static void deallocate(value_type *p, size_t n)
42     { if (0 != n) alloc_type().deallocate(p, n * chunk); }
43   static void deallocate(value_type *p)
44     { alloc_type().deallocate((char*)p, chunk); }
45   
46 IND #undef chunk
47 IND };
48 #endif
49

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:54PM
© Kitware Inc.