@@ -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+ }
183242int 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