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
51class vtkHeapBlock; //forward declaration
52
53class VTKCOMMONMISC_EXPORT vtkHeap : public vtkObject
54{
55public:
56 static vtkHeap *New();
57 vtkTypeMacro(vtkHeap,vtkObject);
58 void PrintSelf(ostream& os, vtkIndent indent) VTK_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
96protected:
98 ~vtkHeap() VTK_OVERRIDE;
99
100 void Add(size_t blockSize);
101 void CleanAll();
102 vtkHeapBlock* DeleteAndNext();
103
104 size_t BlockSize;
105 int NumberOfAllocations;
106 int NumberOfBlocks;
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
116private:
117 vtkHeap(const vtkHeap&) VTK_DELETE_FUNCTION;
118 void operator=(const vtkHeap&) VTK_DELETE_FUNCTION;
119};
120
121#endif
replacement for malloc/free and new/delete
Definition: vtkHeap.h:54
void Reset()
This methods resets the current allocation location back to the beginning of the heap.
virtual void SetBlockSize(size_t)
Set/Get the size at which blocks are allocated.
char * StringDup(const char *str)
Convenience method performs string duplication.
~vtkHeap() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void * AllocateMemory(size_t n)
Allocate the memory requested.
virtual size_t GetBlockSize()
Definition: vtkHeap.h:72
static vtkHeap * New()
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60