ReXGlue SDK
Loading...
Searching...
No Matches
host.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <array>
14#include <cstddef>
15
16#include <rex/platform.h>
17#include <rex/types.h>
18
19namespace rex::memory {
20
22enum class Tag : u8 {
23 kCore = 0,
25};
26
28inline constexpr size_t kMaxTags = 16;
29
30struct TagStats {
31 u64 live_bytes = 0;
32 u64 live_count = 0;
33 u64 peak_bytes = 0;
34 u64 total_count = 0;
35};
36
37struct HostStats {
38 std::array<TagStats, kMaxTags>
39 tags{};
40 TagStats total;
41};
42
50REX_API void* HostAlloc(size_t size, size_t align = 0) noexcept;
51
59REX_API void HostFree(void* ptr, size_t size = 0, size_t align = 0) noexcept;
60
66REX_API size_t HostSize(const void* ptr) noexcept;
67
70
76REX_API void SetAllocStackDepth(i32 depth) noexcept;
77
79[[nodiscard]] REX_API i32 GetAllocStackDepth() noexcept;
80
83
87REX_API const char* GetTagName(Tag tag) noexcept;
88
95REX_API void SetTagName(Tag tag, const char* name) noexcept;
96
99 public:
105 explicit TagScope(Tag tag) noexcept;
106
109
110 TagScope(const TagScope&) = delete;
111 TagScope& operator=(const TagScope&) = delete;
112
113 private:
114 Tag previous_;
115};
116
117namespace detail {
118
120enum class BlockError : u8 {
121 kForeignPointer,
122 kTypeMismatch,
123 kSizeMismatch,
124};
125
127using BlockErrorHandler = void (*)(BlockError error, const void* ptr);
128
135REX_API BlockErrorHandler SetBlockErrorHandler(BlockErrorHandler handler) noexcept;
136
142REX_API void FailNextAllocations(u32 count) noexcept;
143
145enum class AllocType : u8 {
146 kScalar,
147 kArray,
148 kRaw,
149};
150
160REX_API void* NewBlock(size_t size, size_t align, AllocType type, bool can_throw);
161
169REX_API void DeleteBlock(void* ptr, size_t size, AllocType type) noexcept;
170
171} // namespace detail
172
173} // namespace rex::memory
TagScope(Tag tag) noexcept
Definition endian.h:27
size_t HostSize(const void *ptr) noexcept
const char * GetTagName(Tag tag) noexcept
constexpr size_t kMaxTags
Definition host.h:28
void HostFree(void *ptr, size_t size=0, size_t align=0) noexcept
HostStats GetHostStats() noexcept
void SetAllocStackDepth(i32 depth) noexcept
void * HostAlloc(size_t size, size_t align=0) noexcept
i32 GetAllocStackDepth() noexcept
void SetTagName(Tag tag, const char *name) noexcept
Tag GetThreadTag() noexcept
Tag
Definition host.h:22
@ kThirdParty
Definition host.h:24
@ kCore
Definition host.h:23
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Definition host.h:37
std::array< TagStats, kMaxTags > tags
Definition host.h:39
Definition host.h:30
u64 total_count
Definition host.h:34
u64 live_count
Definition host.h:32
u64 live_bytes
Definition host.h:31
u64 peak_bytes
Definition host.h:33
Integer types, byte order wrappers and size literals.