IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
mem_info.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/mem_align.hxx>
7
8namespace ice
9{
10
11 template<typename T>
12 constexpr ice::usize size_of = { sizeof(T) };
13
14 template<typename T>
15 constexpr ice::ualign align_of = static_cast<ice::ualign>(alignof(T));
16
17 template<typename T>
19
22 {
23 return ice::meminfo{ .size = ice::usize{ info.size.value * count }, .alignment = info.alignment };
24 }
25
36 constexpr auto operator+=(ice::meminfo& left, ice::meminfo right) noexcept -> ice::usize
37 {
38 // Align first
39 ice::AlignResult const res = ice::align_to(left.size, right.alignment);
40 left.size = res.value;
41
42 ice::usize const result = left.size;
43 // The following line is commented out on purpose.
44 // We need to keep the original alignment so any allocation made
45 // will mimic all the added meminfo values and respect their offsets.
46 // left.alignment = right.alignment; // DON'T SET THIS
47 left.size += right.size;
48 return result;
49 }
50
51} // namespace ice
Definition info.hxx:8
SPDX-License-Identifier: MIT.
Definition array.hxx:12
constexpr ice::usize size_of
Definition mem_info.hxx:12
constexpr auto operator*(T left, T right) noexcept -> T
Definition strong_type_integral.hxx:96
constexpr auto operator+=(T &left, T right) noexcept -> T &
Definition strong_type_integral.hxx:120
std::uint64_t u64
Definition types.hxx:27
constexpr ice::ualign align_of
Definition mem_info.hxx:15
constexpr auto align_to(T value, ice::ualign alignment) noexcept -> ice::AlignResult< T >
Definition mem_align.hxx:41
constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
Definition base.hxx:43
constexpr ice::meminfo meminfo_of
Definition mem_info.hxx:18
ualign
Definition mem_size_types.hxx:39
Definition mem_align.hxx:13
T value
Definition mem_align.hxx:14
Definition mem_size_types.hxx:59
Represents a unsigned size value on the given platform.
Definition mem_size_types.hxx:26