mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
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 |
||
|---|---|---|
| .. | ||
| intern | ||
| CMakeLists.txt | ||
| MEM_alloc_string_storage.hh | ||
| MEM_Allocator.h | ||
| MEM_CacheLimiter.h | ||
| MEM_CacheLimiterC-Api.h | ||
| MEM_RefCounted.h | ||
| MEM_RefCountedC-Api.h | ||