Skip to content

Commit b77494d

Browse files
committed
Removed use of Allocator::setMemoryTracking(..)
1 parent 9d3ae99 commit b77494d

File tree

6 files changed

+86
-31
lines changed

6 files changed

+86
-31
lines changed

examples/app/vsgviewer/vsgviewer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ int main(int argc, char** argv)
7272
windowTraits->apiDumpLayer = arguments.read({"--api", "-a"});
7373
windowTraits->synchronizationLayer = arguments.read("--sync");
7474
bool reportAverageFrameRate = arguments.read("--fps");
75-
if (int mt = 0; arguments.read({"--memory-tracking", "--mt"}, mt)) vsg::Allocator::instance()->setMemoryTracking(mt);
7675
if (arguments.read("--double-buffer")) windowTraits->swapchainPreferences.imageCount = 2;
7776
if (arguments.read("--triple-buffer")) windowTraits->swapchainPreferences.imageCount = 3; // default
7877
if (arguments.read("--IMMEDIATE")) { windowTraits->swapchainPreferences.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; }

examples/commands/vsgocclusionquery/vsgocclusionquery.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ int main(int argc, char** argv)
2929
windowTraits->windowTitle = "vsgocclusionquery";
3030
windowTraits->debugLayer = arguments.read({"--debug", "-d"});
3131
windowTraits->apiDumpLayer = arguments.read({"--api", "-a"});
32-
if (int mt = 0; arguments.read({"--memory-tracking", "--mt"}, mt)) vsg::Allocator::instance()->setMemoryTracking(mt);
3332
if (arguments.read("--double-buffer")) windowTraits->swapchainPreferences.imageCount = 2;
3433
if (arguments.read("--triple-buffer")) windowTraits->swapchainPreferences.imageCount = 3; // default
3534
if (arguments.read("--IMMEDIATE")) windowTraits->swapchainPreferences.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;

examples/commands/vsgtimestamps/vsgtimestamps.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ int main(int argc, char** argv)
2929
windowTraits->windowTitle = "vsgtimestamps";
3030
windowTraits->debugLayer = arguments.read({"--debug", "-d"});
3131
windowTraits->apiDumpLayer = arguments.read({"--api", "-a"});
32-
if (int mt = 0; arguments.read({"--memory-tracking", "--mt"}, mt)) vsg::Allocator::instance()->setMemoryTracking(mt);
3332
if (arguments.read("--double-buffer")) windowTraits->swapchainPreferences.imageCount = 2;
3433
if (arguments.read("--triple-buffer")) windowTraits->swapchainPreferences.imageCount = 3; // default
3534
if (arguments.read("--IMMEDIATE")) windowTraits->swapchainPreferences.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;

examples/core/vsgallocator/vsgallocator.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,44 @@
99
#include <iostream>
1010
#include <thread>
1111

12-
class CustomAllocator : public vsg::Allocator
12+
class StdAllocator : public vsg::Allocator
1313
{
1414
public:
15-
CustomAllocator(std::unique_ptr<Allocator> in_nestedAllocator = {}) :
15+
StdAllocator(std::unique_ptr<Allocator> in_nestedAllocator = {}) :
1616
vsg::Allocator(std::move(in_nestedAllocator))
1717
{
18-
if (memoryTracking & vsg::MEMORY_TRACKING_REPORT_ACTIONS)
19-
{
20-
std::cout << "CustomAllocator()" << this << std::endl;
21-
}
2218
}
2319

24-
~CustomAllocator()
20+
~StdAllocator()
2521
{
26-
if (memoryTracking & vsg::MEMORY_TRACKING_REPORT_ACTIONS)
27-
{
28-
std::cout << "~CustomAllocator() " << this << std::endl;
29-
}
3022
}
3123

3224
void report(std::ostream& out) const override
3325
{
34-
std::cout << "CustomAllocator::report() " << allocatorMemoryBlocks.size() << std::endl;
35-
vsg::Allocator::report(out);
26+
out << "StdAllocator::report() " << std::endl;
3627
}
3728

38-
void* allocate(std::size_t size, vsg::AllocatorAffinity allocatorAffinity = vsg::ALLOCATOR_AFFINITY_OBJECTS) override
29+
void* allocate(std::size_t size, vsg::AllocatorAffinity) override
3930
{
40-
void* ptr = Allocator::allocate(size, allocatorAffinity);
41-
if (memoryTracking & vsg::MEMORY_TRACKING_REPORT_ACTIONS)
42-
{
43-
std::cout << "CustomAllocator::allocate(" << size << ", " << allocatorAffinity << ") ptr = " << ptr << std::endl;
44-
}
45-
return ptr;
31+
return operator new (size); //, std::align_val_t{default_alignment});
4632
}
4733

4834
bool deallocate(void* ptr, std::size_t size) override
4935
{
50-
if (memoryTracking & vsg::MEMORY_TRACKING_REPORT_ACTIONS)
51-
{
52-
std::cout << "CustomAllocator::deallocate(" << ptr << ")" << std::endl;
53-
}
54-
return Allocator::deallocate(ptr, size);
36+
if (nestedAllocator && nestedAllocator->deallocate(ptr, size)) return true;
37+
38+
operator delete (ptr);//, std::align_val_t{default_alignment});
39+
return true;
5540
}
41+
42+
size_t deleteEmptyMemoryBlocks() override { return 0; }
43+
size_t totalAvailableSize() const override { return 0; }
44+
size_t totalReservedSize() const override { return 0; }
45+
size_t totalMemorySize() const override { return 0; }
46+
void setBlockSize(vsg::AllocatorAffinity, size_t) {}
5647
};
5748

49+
5850
struct SceneStatistics : public vsg::Inherit<vsg::ConstVisitor, SceneStatistics>
5951
{
6052
std::map<const char*, size_t> objectCounts;
@@ -77,8 +69,7 @@ int main(int argc, char** argv)
7769
vsg::CommandLine arguments(&argc, argv);
7870

7971
// Allocaotor related command line settings
80-
if (arguments.read("--custom")) vsg::Allocator::instance().reset(new CustomAllocator(std::move(vsg::Allocator::instance())));
81-
if (int mt; arguments.read({"--memory-tracking", "--mt"}, mt)) vsg::Allocator::instance()->setMemoryTracking(mt);
72+
if (arguments.read("--std")) vsg::Allocator::instance().reset(new StdAllocator(std::move(vsg::Allocator::instance())));
8273
if (int type; arguments.read("--allocator", type)) vsg::Allocator::instance()->allocatorType = vsg::AllocatorType(type);
8374
if (size_t objectsBlockSize; arguments.read("--objects", objectsBlockSize)) vsg::Allocator::instance()->setBlockSize(vsg::ALLOCATOR_AFFINITY_OBJECTS, objectsBlockSize);
8475
if (size_t nodesBlockSize; arguments.read("--nodes", nodesBlockSize)) vsg::Allocator::instance()->setBlockSize(vsg::ALLOCATOR_AFFINITY_NODES, nodesBlockSize);

examples/nodes/vsgannotation/vsgannotation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ int main(int argc, char** argv)
108108
windowTraits->apiDumpLayer = arguments.read({"--api", "-a"});
109109
windowTraits->synchronizationLayer = arguments.read("--sync");
110110
bool reportAverageFrameRate = arguments.read("--fps");
111-
if (int mt = 0; arguments.read({"--memory-tracking", "--mt"}, mt)) vsg::Allocator::instance()->setMemoryTracking(mt);
112111
if (arguments.read("--double-buffer")) windowTraits->swapchainPreferences.imageCount = 2;
113112
if (arguments.read("--triple-buffer")) windowTraits->swapchainPreferences.imageCount = 3; // default
114113
if (arguments.read("--IMMEDIATE")) { windowTraits->swapchainPreferences.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; }

examples/nodes/vsggroups/vsggroups.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,83 @@ std::shared_ptr<experimental::SharedPtrNode> createSharedPtrQuadTree(unsigned in
180180
return t;
181181
}
182182

183+
184+
// consider tcmalloc? https://goog-perftools.sourceforge.net/doc/tcmalloc.html
185+
// consider Alloc https://www.codeproject.com/Articles/1084801/Replace-malloc-free-with-a-Fast-Fixed-Block-Memory
186+
class StdAllocator : public vsg::Allocator
187+
{
188+
public:
189+
StdAllocator(std::unique_ptr<Allocator> in_nestedAllocator = {}) :
190+
vsg::Allocator(std::move(in_nestedAllocator))
191+
{
192+
}
193+
194+
~StdAllocator()
195+
{
196+
}
197+
198+
void report(std::ostream& out) const override
199+
{
200+
out << "StdAllocator::report() " << std::endl;
201+
}
202+
203+
void* allocate(std::size_t size, vsg::AllocatorAffinity) override
204+
{
205+
return operator new (size); //, std::align_val_t{default_alignment});
206+
}
207+
208+
bool deallocate(void* ptr, std::size_t size) override
209+
{
210+
if (nestedAllocator && nestedAllocator->deallocate(ptr, size)) return true;
211+
212+
operator delete (ptr);//, std::align_val_t{default_alignment});
213+
return true;
214+
}
215+
216+
size_t deleteEmptyMemoryBlocks() override { return 0; }
217+
size_t totalAvailableSize() const override { return 0; }
218+
size_t totalReservedSize() const override { return 0; }
219+
size_t totalMemorySize() const override { return 0; }
220+
void setBlockSize(vsg::AllocatorAffinity, size_t) {}
221+
};
222+
223+
const size_t KB = 1024;
224+
const size_t MB = 1024 * KB;
225+
const size_t GB = 1024 * MB;
226+
227+
struct Units
228+
{
229+
Units(size_t v) : value(v) {}
230+
231+
size_t value;
232+
};
233+
234+
std::ostream& operator<<(std::ostream& out, const Units& size)
235+
{
236+
if (size.value>GB) out << static_cast<double>(size.value)/static_cast<double>(GB) << " gigabytes";
237+
else if (size.value>MB) out << static_cast<double>(size.value)/static_cast<double>(MB) << " megabytes";
238+
else if (size.value>KB) out << static_cast<double>(size.value)/static_cast<double>(KB) <<" kilobytes";
239+
else out << size.value<<" bytes";
240+
return out;
241+
}
183242
int main(int argc, char** argv)
184243
{
185244
vsg::CommandLine arguments(&argc, argv);
245+
if (arguments.read("--std")) vsg::Allocator::instance().reset(new StdAllocator(std::move(vsg::Allocator::instance())));
246+
186247
auto numLevels = arguments.value(11u, {"-l", "--levels"});
187248
auto numTraversals = arguments.value(10u, {"-t", "--traversals"});
188249
auto type = arguments.value(std::string("vsg::Group"), "--type");
189250
auto quiet = arguments.read("-q");
190251
auto inputFilename = arguments.value<vsg::Path>("", "-i");
191252
auto outputFilename = arguments.value<vsg::Path>("", "-o");
253+
254+
size_t unit = arguments.value<size_t>(MB, "--unit");
255+
if (int allocatorType; arguments.read("--allocator", allocatorType)) vsg::Allocator::instance()->allocatorType = vsg::AllocatorType(allocatorType);
256+
if (size_t objectsBlockSize; arguments.read("--objects", objectsBlockSize)) vsg::Allocator::instance()->setBlockSize(vsg::ALLOCATOR_AFFINITY_OBJECTS, objectsBlockSize * unit);
257+
if (size_t nodesBlockSize; arguments.read("--nodes", nodesBlockSize)) vsg::Allocator::instance()->setBlockSize(vsg::ALLOCATOR_AFFINITY_NODES, nodesBlockSize * unit);
258+
if (size_t dataBlockSize; arguments.read("--data", dataBlockSize)) vsg::Allocator::instance()->setBlockSize(vsg::ALLOCATOR_AFFINITY_DATA, dataBlockSize * unit);
259+
192260
vsg::ref_ptr<vsg::RecordTraversal> vsg_recordTraversal(arguments.read("-d") ? new vsg::RecordTraversal : nullptr);
193261
vsg::ref_ptr<VsgConstVisitor> vsg_ConstVisitor(arguments.read("-c") ? new VsgConstVisitor : nullptr);
194262
if (arguments.errors()) return arguments.writeErrorMessages(std::cerr);

0 commit comments

Comments
 (0)