VTK  9.1.0
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) 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() 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
116private:
117 vtkHeap(const vtkHeap&) = delete;
118 void operator=(const vtkHeap&) = delete;
119};
120
121#endif
replacement for malloc/free and new/delete
Definition: vtkHeap.h:54
size_t Alignment
Definition: vtkHeap.h:107
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.
int NumberOfBlocks
Definition: vtkHeap.h:106
char * StringDup(const char *str)
Convenience method performs string duplication.
vtkHeapBlock * DeleteAndNext()
size_t Position
Definition: vtkHeap.h:114
vtkHeapBlock * Current
Definition: vtkHeap.h:112
~vtkHeap() override
vtkHeapBlock * First
Definition: vtkHeap.h:110
void Add(size_t blockSize)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
size_t BlockSize
Definition: vtkHeap.h:104
void CleanAll()
void * AllocateMemory(size_t n)
Allocate the memory requested.
int NumberOfAllocations
Definition: vtkHeap.h:105
virtual size_t GetBlockSize()
Set/Get the size at which blocks are allocated.
Definition: vtkHeap.h:72
static vtkHeap * New()
vtkHeapBlock * Last
Definition: vtkHeap.h:111
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73