blender/intern/clog
Brecht Van Lommel b26e16e151 Refactor: Unify memory API to MEM_new and MEM_delete variations
This change removes the need to to carefully pair MEM_mallocN/MEM_new_for_free
with MEM_freeN and MEM_new with MEM_delete. Instead all function are now
variations of MEM_new and MEM_delete.

* MEM_new_for_free -> MEM_new
* MEM_mallocN -> MEM_new_uninitialized
* MEM_callocN -> MEM_new_zeroed
* MEM_freeN -> MEM_delete (for typed pointers)
* MEM_freeN -> MEM_delete_void (for void pointers)
* MEM_reallocN -> MEM_realloc_uninitialized
* MEM_recallocN -> MEM_realloc_zeroed
* MEM_dupallocN -> MEM_new (when possible)
* MEM_dupallocN -> MEM_dupalloc (for typed pointers)
* MEM_dupallocN -> MEM_dupalloc_void (for void pointers)

The MEM_malloc and MEM_calloc functions were renamed to make it clear that
they should be paired with MEM_delete and to clarify what they do.

The compiler will emit an error if MEM_delete or MEM_delete_void is used on
the wrong pointer type. However a remaining risk is casting a MEM_new allocation
with a non-trivial destructor to a void pointer (which is the same as before). This is
why MEM_delete_void and MEM_dupalloc_void exist as a separate functions,
to identify legacy code that has this risk and should be eliminated over time.

Note that MEM_new_array only supports trivially destructible types. This
avoids the need for an equivalent of the delete [] operator and the associated
mistakes that can be made. Instead MEM_delete can be used for everything. For
non-trivial types, data structures like Vector should be used instead.

MEM_dupalloc is now also more type safe. As before it is only supported on
trivially copyable types, and this is now enforced through static asserts to
prevent mistakes. It is also templated to remove the need for casts.

Pull Request: https://projects.blender.org/blender/blender/pulls/151387
2026-01-26 19:20:33 +01:00
..
CLG_log.h Logging: Add argument to list all available categories 2025-09-26 17:33:26 +02:00
clog.cc Refactor: Unify memory API to MEM_new and MEM_delete variations 2026-01-26 19:20:33 +01:00
CMakeLists.txt Refactor: Clog: Port to C++ 2025-07-09 20:59:23 +02:00