/**************************************************************************/ /* memory.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #ifndef MEMORY_H #define MEMORY_H #include "core/error/error_macros.h" #include "core/templates/safe_refcount.h" #include <stddef.h> #include <new> #include <type_traits> class Memory { … }; class DefaultAllocator { … }; void *operator new(size_t p_size, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory #ifdef _MSC_VER // When compiling with VC++ 2017, the above declarations of placement new generate many irrelevant warnings (C4291). // The purpose of the following definitions is to muffle these warnings, not to provide a usable implementation of placement delete. void operator delete(void *p_mem, const char *p_description); void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)); void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description); #endif #define memalloc(m_size) … #define memrealloc(m_mem, m_size) … #define memfree(m_mem) … _ALWAYS_INLINE_ void postinitialize_handler(void *) { … } template <typename T> _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { … } #define memnew(m_class) … #define memnew_allocator(m_class, m_allocator) … #define memnew_placement(m_placement, m_class) … _ALWAYS_INLINE_ bool predelete_handler(void *) { … } template <typename T> void memdelete(T *p_class) { … } template <typename T, typename A> void memdelete_allocator(T *p_class) { … } #define memdelete_notnull(m_v) … #define memnew_arr(m_class, m_count) … _FORCE_INLINE_ uint64_t *_get_element_count_ptr(uint8_t *p_ptr) { … } template <typename T> T *memnew_arr_template(size_t p_elements) { … } /** * Wonders of having own array functions, you can actually check the length of * an allocated-with memnew_arr() array */ template <typename T> size_t memarr_len(const T *p_class) { … } template <typename T> void memdelete_arr(T *p_class) { … } struct _GlobalNil { … }; struct _GlobalNilClass { … }; template <typename T> class DefaultTypedAllocator { … }; #endif // MEMORY_H