vsg-dev / VulkanSceneGraph

Vulkan & C++17 based Scene Graph Project
http://www.vulkanscenegraph.org
MIT License
1.32k stars 212 forks source link

Feature: Set/Get custom allocation functions for STL containers and such #506

Closed WSSDude closed 2 years ago

WSSDude commented 2 years ago

Is your feature request related to a problem? Please describe. Trying to use custom allocator used by engine with VulkanSceneGraph to make it use its custom memory manager which has some debug features built into it for debug builds among other things. Also, this custom memory manager is more efficient in context of said engine than what standard library provides.

Describe the solution you'd like It would be nice if there was some functions added to get/set allocation functions used by internal containers and such. From what I looked at, there are some STL containers used, which can be passed in custom allocator as template argument.

What I would propose is to create some templated allocator class which would function as redirection to some saved functions for allocate and free (which could be defaulted to malloc and free or some other wrapper functions with same functionality). Added functions for setting/getting these would manipulate these saved functions only, all instances of allocator should be able to automatically use it (some global/singleton probably?).

Had not considered yet exact integration, but I would probably do something along the lines above, and use this allocator wrapper whenever possible (so each definition of std::vector would have allocator properly set etc.).

Describe alternatives you've considered Just ignore this issue, but that would hinder flexibility and leave some potential performance on the table, at least for advanced use cases.

robertosfield commented 2 years ago

vsg::Allocator?

The VSG has purpose built allocatr that is designed for optimizing runtime peformance by block allocation and allocating objects with similar access timing together. I wrote extensively about it on vsg-users. There is also the vsgallovator example.

You can implement your own vsg::Allocator so potentially extend it for debugging purposes.