VTK: Common/Misc/vtkHeap.h Source File

| VTK 9.3.1

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
39 VTK_ABI_NAMESPACE_BEGIN
40 class vtkHeapBlock; // forward declaration
41
42 class VTKCOMMONMISC_EXPORT vtkHeap : public vtkObject
43 {
44 public:
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
85 protected:
86 vtkHeap();
87 ~vtkHeap() override;
88
89 void Add(size_t blockSize);
90 void CleanAll();
91 vtkHeapBlock* DeleteAndNext();
92
93 size_t BlockSize;
94 int NumberOfAllocations;
95 int NumberOfBlocks;
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
105 private:
106 vtkHeap(const vtkHeap&) = delete;
107 void operator=(const vtkHeap&) = delete;
108 };
109
110 VTK_ABI_NAMESPACE_END
111 #endif
vtkHeap
replacement for malloc/free and new/delete
Definition: vtkHeap.h:43
vtkHeap::Alignment
size_t Alignment
Definition: vtkHeap.h:96
vtkHeap::Reset
void Reset()
This methods resets the current allocation location back to the beginning of the heap.
vtkHeap::SetBlockSize
virtual void SetBlockSize(size_t)
Set/Get the size at which blocks are allocated.
vtkHeap::New
static vtkHeap * New()
vtkHeap::NumberOfBlocks
int NumberOfBlocks
Definition: vtkHeap.h:95
vtkHeap::AllocateMemory
void * AllocateMemory(size_t n)
Allocate the memory requested.
vtkHeap::StringDup
char * StringDup(const char *str)
Convenience method performs string duplication.
vtkHeap::Position
size_t Position
Definition: vtkHeap.h:103
vtkHeap::Current
vtkHeapBlock * Current
Definition: vtkHeap.h:101
vtkHeap::~vtkHeap
~vtkHeap() override
vtkHeap::First
vtkHeapBlock * First
Definition: vtkHeap.h:99
vtkHeap::vtkHeap
vtkHeap()
vtkHeap::Add
void Add(size_t blockSize)
vtkHeap::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkHeap::BlockSize
size_t BlockSize
Definition: vtkHeap.h:93
vtkHeap::CleanAll
void CleanAll()
vtkHeap::DeleteAndNext
vtkHeapBlock * DeleteAndNext()
vtkHeap::NumberOfAllocations
int NumberOfAllocations
Definition: vtkHeap.h:94
vtkHeap::GetBlockSize
virtual size_t GetBlockSize()
Set/Get the size at which blocks are allocated.
Definition: vtkHeap.h:61
vtkHeap::Last
vtkHeapBlock * Last
Definition: vtkHeap.h:100
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkObject.h