VTK  9.3.20240425
vtkHeap.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
33#ifndef vtkHeap_h
34#define vtkHeap_h
35
36#include "vtkCommonMiscModule.h" // For export macro
37#include "vtkObject.h"
38
39VTK_ABI_NAMESPACE_BEGIN
40class vtkHeapBlock; // forward declaration
41
42class VTKCOMMONMISC_EXPORT vtkHeap : public vtkObject
43{
44public:
45 static vtkHeap* New();
46 vtkTypeMacro(vtkHeap, vtkObject);
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
52 void* AllocateMemory(size_t n);
53
55
60 virtual void SetBlockSize(size_t);
61 virtual size_t GetBlockSize() { return this->BlockSize; }
63
65
68 vtkGetMacro(NumberOfBlocks, int);
69 vtkGetMacro(NumberOfAllocations, int);
71
78 void Reset();
79
83 char* StringDup(const char* str);
84
85protected:
87 ~vtkHeap() override;
88
89 void Add(size_t blockSize);
90 void CleanAll();
91 vtkHeapBlock* DeleteAndNext();
92
93 size_t BlockSize;
96 size_t Alignment;
97
98 // Manage the blocks
99 vtkHeapBlock* First;
100 vtkHeapBlock* Last;
101 vtkHeapBlock* Current;
102 // Manage the memory in the block
103 size_t Position; // the position in the Current block
104
105private:
106 vtkHeap(const vtkHeap&) = delete;
107 void operator=(const vtkHeap&) = delete;
108};
109
110VTK_ABI_NAMESPACE_END
111#endif
replacement for malloc/free and new/delete
Definition vtkHeap.h:43
size_t Alignment
Definition vtkHeap.h:96
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:95
char * StringDup(const char *str)
Convenience method performs string duplication.
vtkHeapBlock * DeleteAndNext()
size_t Position
Definition vtkHeap.h:103
vtkHeapBlock * Current
Definition vtkHeap.h:101
~vtkHeap() override
vtkHeapBlock * First
Definition vtkHeap.h:99
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:93
void CleanAll()
void * AllocateMemory(size_t n)
Allocate the memory requested.
int NumberOfAllocations
Definition vtkHeap.h:94
virtual size_t GetBlockSize()
Set/Get the size at which blocks are allocated.
Definition vtkHeap.h:61
static vtkHeap * New()
vtkHeapBlock * Last
Definition vtkHeap.h:100
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162