Improve consistency of MEM_guardedalloc usage in C++ code #124512
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#124512
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The usage of our guarded allocator code with C++ data creation (
new
/delete
) is confusing at best in current code.MEM_new
: Allocates required amount of memory (using guardedalloc code) and calls the default 'placement new' operation on it.MEM_CXX_CLASS_ALLOC_FUNCS
: This macro defines new/delete operators for a given C++ type, using the guardedalloc code. Most of its usages are conditioned by the CMakeWITH_CXX_GUARDEDALLOC
setting.WITH_CXX_GUARDEDALLOC
: This CMake setting also conditions the global override of new/delete operators to use guardedalloc code. It is disabled by default.The fact that
WITH_CXX_GUARDEDALLOC
is disabled by default means that it is barely ever used. Often enabling it will reveal some memory management issues.The global overriding of
new
/delete
operators is most likely not worth the risk of inconsistencies (it makes it too easy to run into situations where some data allocated from a linked library with 'normal' new gets deleted by the 'guardedalloc' new e.g.)Proposal
WITH_CXX_GUARDEDALLOC
: There should not be an option to disable guardedalloc in most common cases.new
/delete
.MEM_CXX_CLASS_ALLOC_FUNCS
where it is currently used.Question
Do we want to keep the two current systems (
MEM_new
/MEM_delete
andMEM_CXX_CLASS_ALLOC_FUNCS
)?MEM_new
/MEM_delete
has the advantage of being 'universal', and allows to control where usage of guardedalloc is desired, and where standardnew
allocation can be used instead.MEM_CXX_CLASS_ALLOC_FUNCS
allows to use standard new/delete C++ code for Blender C++ types, while automatically using the guardedallocator.I'm not fully sure yet. It's nice that with
MEM_CXX_CLASS_ALLOC_FUNCS
one can just use normalstd::make_unique
etc. Could make our own version of that though, but that doesn't seem nice. I also still have to check how overridingoperator new
works with child classes.Just wanted to mention some downsides of
MEM_CXX_CLASS_ALLOC_FUNCS
:new
seems to expect in some cases (see__STDCPP_DEFAULT_NEW_ALIGNMENT__
).TBH, since we entered the ASAN era, I very rarely use/need our guardedallocation name info anymore?
WIP: Improve consistency of MEM_guardedalloc usage in C++ codeto Improve consistency of MEM_guardedalloc usage in C++ code