IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_debug_allocator.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/module.hxx>
8
9namespace ice::detail
10{
11
13 {
14 static constexpr ice::StringID Constant_APIName = "iceshard.task.debug-api"_sid;
15 static constexpr ice::u32 Constant_APIVersion = 1;
16
19 };
20
21#if !ICE_RELEASE
22 struct TaskDebugAllocator final : public ice::Module<TaskDebugAllocator>
23 {
24 static auto pool() noexcept -> ice::String
25 {
26 return _allocator_pool.not_empty() ? _allocator_pool : "Tasks";
27 }
28
29 static auto allocator() noexcept -> ice::Allocator&
30 {
31 static HostAllocator fallback_alloc;
32 return _allocator_ptr ? *_allocator_ptr : fallback_alloc;
33 }
34
35 static auto allocate(size_t size) noexcept -> void*
36 {
37 return allocator().allocate(ice::usize{ size }).memory;
38 }
39
40 static void deallocate(void* pointer) noexcept
41 {
42 allocator().deallocate(pointer);
43 }
44
45 static bool on_load(ice::Allocator& alloc, ice::ModuleNegotiator auto const& negotiator) noexcept
46 {
48 if (negotiator.query_api(api))
49 {
50 _allocator_ptr = api.allocator_ptr;
51 _allocator_pool = api.allocator_pool;
52 }
53 return true;
54 }
55
56 static void on_unload(ice::Allocator& alloc) noexcept
57 {
58 _allocator_ptr = nullptr;
59 }
60
62
63 private:
64 static inline ice::Allocator* _allocator_ptr{ };
65 static inline ice::String _allocator_pool;
66 };
67#endif
68
69} // namespace ice
Definition mem_allocator_host.hxx:11
Base class for modules that will automatically register them to be loaded by the module manager.
Definition module.hxx:17
Definition devui_module.hxx:16
Definition hashmap_details.hxx:13
SPDX-License-Identifier: MIT.
Definition array.hxx:12
ice::BasicString< char > String
Definition string.hxx:82
auto alloc(ice::usize size) noexcept -> ice::AllocResult
BaseStringID< ice::build::Constant_StringID_DebugInfoEnabled > StringID
\copy ice::BaseStringID.
Definition stringid.hxx:15
std::uint32_t u32
Definition types.hxx:26
ice::AllocatorBase< ice::build::is_debug||ice::build::is_develop > Allocator
Definition mem_types.hxx:25
Definition task_debug_allocator.hxx:13
ice::String allocator_pool
Definition task_debug_allocator.hxx:18
static constexpr ice::StringID Constant_APIName
Definition task_debug_allocator.hxx:14
ice::Allocator * allocator_ptr
Definition task_debug_allocator.hxx:17
static constexpr ice::u32 Constant_APIVersion
Definition task_debug_allocator.hxx:15
Definition task_debug_allocator.hxx:23
static auto allocator() noexcept -> ice::Allocator &
Definition task_debug_allocator.hxx:29
static auto allocate(size_t size) noexcept -> void *
Definition task_debug_allocator.hxx:35
static bool on_load(ice::Allocator &alloc, ice::ModuleNegotiator auto const &negotiator) noexcept
Definition task_debug_allocator.hxx:45
static void deallocate(void *pointer) noexcept
Definition task_debug_allocator.hxx:40
static auto pool() noexcept -> ice::String
Definition task_debug_allocator.hxx:24
static void on_unload(ice::Allocator &alloc) noexcept
Definition task_debug_allocator.hxx:56
IS_WORKAROUND_MODULE_INITIALIZATION(TaskDebugAllocator)
Represents a unsigned size value on the given platform.
Definition mem_size_types.hxx:26