VTK
vtkHeap.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHeap.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
45 #ifndef vtkHeap_h
46 #define vtkHeap_h
47 
48 #include "vtkCommonMiscModule.h" // For export macro
49 #include "vtkObject.h"
50 
51 class vtkHeapBlock; //forward declaration
52 
53 class VTKCOMMONMISC_EXPORT vtkHeap : public vtkObject
54 {
55 public:
56  static vtkHeap *New();
57  vtkTypeMacro(vtkHeap,vtkObject);
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
63  void* AllocateMemory(size_t n);
64 
66 
71  virtual void SetBlockSize(size_t);
72  virtual size_t GetBlockSize() { return this->BlockSize;};
74 
76 
79  vtkGetMacro(NumberOfBlocks,int);
80  vtkGetMacro(NumberOfAllocations,int);
82 
89  void Reset();
90 
94  char* StringDup(const char* str);
95 
96 protected:
97  vtkHeap();
98  ~vtkHeap() override;
99 
100  void Add(size_t blockSize);
101  void CleanAll();
102  vtkHeapBlock* DeleteAndNext();
103 
104  size_t BlockSize;
107  size_t Alignment;
108 
109  // Manage the blocks
110  vtkHeapBlock* First;
111  vtkHeapBlock* Last;
112  vtkHeapBlock* Current;
113  // Manage the memory in the block
114  size_t Position; //the position in the Current block
115 
116 private:
117  vtkHeap(const vtkHeap&) = delete;
118  void operator=(const vtkHeap&) = delete;
119 };
120 
121 #endif
int NumberOfBlocks
Definition: vtkHeap.h:106
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkHeapBlock * Current
Definition: vtkHeap.h:112
vtkHeapBlock * First
Definition: vtkHeap.h:110
vtkHeapBlock * Last
Definition: vtkHeap.h:111
a simple class to control print indentation
Definition: vtkIndent.h:39
int NumberOfAllocations
Definition: vtkHeap.h:105
virtual size_t GetBlockSize()
Set/Get the size at which blocks are allocated.
Definition: vtkHeap.h:72
size_t Position
Definition: vtkHeap.h:114
replacement for malloc/free and new/delete
Definition: vtkHeap.h:53
size_t BlockSize
Definition: vtkHeap.h:104
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
size_t Alignment
Definition: vtkHeap.h:107