Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
memory.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <optional>
7#include <source_location>
8
9namespace helios::profile {
10
11/**
12 * @brief Profile an allocation of memory.
13 * @param ptr The pointer to the allocated memory
14 * @param size The size of the allocated memory
15 * @param name The name of the allocation, used for grouping in the profiler
16 * @param depth The depth of the allocation, used for grouping in the profiler
17 * @param loc The source location of the allocation, used for grouping in the
18 * profiler
19 */
20inline void Alloc(
21 const void* ptr, size_t size, std::optional<CStringView> name, int depth,
22 std::source_location loc = std::source_location::current()) noexcept {
23 Profiler::Instance().Alloc(ptr, size, name, depth, loc);
24}
25
26/**
27 * @brief Profile a deallocation of memory.
28 * @param ptr The pointer to the deallocated memory
29 * @param name The name of the deallocation, used for grouping in the profiler
30 * @param depth The depth of the deallocation, used for grouping in the profiler
31 * @param loc The source location of the deallocation, used for grouping in the
32 * profiler
33 */
34inline void Free(
35 const void* ptr, std::optional<CStringView> name, int depth,
36 std::source_location loc = std::source_location::current()) noexcept {
37 Profiler::Instance().Free(ptr, name, depth, loc);
38}
39
40/**
41 * @brief Profile memory discard.
42 * @param name The name of the memory discard, used for grouping in the profiler
43 */
44inline void MemoryDiscard(CStringView name) noexcept {
46}
47
48/**
49 * @brief Profile memory discard with depth.
50 * @param name The name of the memory discard, used for grouping in the profiler
51 * @param depth The depth of the memory discard, used for grouping in the
52 * profiler
53 */
54inline void MemoryDiscardS(CStringView name, int depth) noexcept {
55 Profiler::Instance().MemoryDiscard(name, depth);
56}
57
58} // namespace helios::profile
static Profiler & Instance() noexcept
Returns the singleton profiler instance.
Definition profiler.hpp:403
void Free(const void *ptr, std::optional< CStringView > name, int depth, std::source_location loc) noexcept
Dispatches a deallocation event to all registered backends.
Definition profiler.cpp:275
void Alloc(const void *ptr, size_t size, std::optional< CStringView > name, int depth, std::source_location loc) noexcept
Dispatches an allocation event to all registered backends.
Definition profiler.cpp:262
void MemoryDiscard(CStringView name) noexcept
Dispatches a memory discard event to all registered backends.
Definition profiler.cpp:287
void Alloc(const void *ptr, size_t size, std::optional< CStringView > name, int depth, std::source_location loc=std::source_location::current()) noexcept
Profile an allocation of memory.
Definition memory.hpp:20
void Free(const void *ptr, std::optional< CStringView > name, int depth, std::source_location loc=std::source_location::current()) noexcept
Profile a deallocation of memory.
Definition memory.hpp:34
void MemoryDiscardS(CStringView name, int depth) noexcept
Profile memory discard with depth.
Definition memory.hpp:54
void MemoryDiscard(CStringView name) noexcept
Profile memory discard.
Definition memory.hpp:44
BasicCStringView< char > CStringView
A view of a null-terminated C string.