// // YaPB - Counter-Strike Bot based on PODBot by Markus Klinge. // Copyright © 2004-2020 YaPB Project . // // SPDX-License-Identifier: MIT // #pragma once #include #include #include // provide placment new to avoid stdc++ header inline void *operator new (const size_t, void *ptr) noexcept { return ptr; } CR_NAMESPACE_BEGIN // internal memory manager class Memory final { public: Memory () = default; ~Memory () = default; public: template static T *get (const size_t length = 1) { auto memory = reinterpret_cast (malloc (cr::max (1u, length * sizeof (T)))); if (!memory) { plat.abort (); } return memory; } template static void release (T *memory) { free (memory); memory = nullptr; } public: template static void construct (T *memory, Args &&...args) { new (memory) T (cr::forward (args)...); } template static void destruct (T *memory) { memory->~T (); } }; CR_NAMESPACE_END