5#ifndef FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
6#define FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
29template <
size_t Period>
43 template <
class T,
class = std::enable_if_t<std::is_arithmetic_v<T>>>
45 : bytes_(
std::ceil(size) * Period) {}
55 template <
size_t OtherPeriod>
67 : bytes_(byte_size) {}
90 template <
class AllocationSize>
101 explicit constexpr operator bool()
const {
return bytes_ != 0u; }
126 uint64_t bytes_ = {};
135 explicit constexpr Bytes(uint64_t size)
151inline namespace allocation_size_literals {
154constexpr Bytes operator""_bytes(
unsigned long long int size) {
159constexpr KiloBytes operator""_kb(
unsigned long long int size) {
164constexpr MegaBytes operator""_mb(
unsigned long long int size) {
169constexpr GigaBytes operator""_gb(
unsigned long long int size) {
174constexpr KibiBytes operator""_kib(
unsigned long long int size) {
179constexpr MebiBytes operator""_mib(
unsigned long long int size) {
184constexpr GibiBytes operator""_gib(
unsigned long long int size) {
Represents the size of an allocation in different units.
constexpr AllocationSize(uint64_t byte_size, FromBytesTag)
Create an allocation size with the amount directly specified in bytes.
constexpr AllocationSize & operator+=(const AllocationSize &other)
constexpr double GetSize() const
constexpr AllocationSize ConvertTo()
Convert the allocation size from one unit to another.
constexpr AllocationSize operator-(const AllocationSize &other) const
constexpr uint64_t GetByteSize() const
constexpr AllocationSize operator+(const AllocationSize &other) const
constexpr AllocationSize(T size)
Create an allocation size with the amount in the Period number of bytes.
constexpr AllocationSize & operator-=(const AllocationSize &other)
constexpr AllocationSize()=default
Create a zero allocation size.
constexpr AllocationSize(const AllocationSize< OtherPeriod > &other)
Create an allocation size from another instance with a different period.
constexpr auto operator<=>(const AllocationSize &other) const =default
constexpr Bytes(uint64_t size)
constexpr Bytes(AllocationSize< 1u > size)
constexpr Bytes()=default
AllocationSize< 1 '024u *1 '024u > MebiBytes
AllocationSize< 1 '024u *1 '024u *1 '024u > GibiBytes
AllocationSize< 1 '000u *1 '000u *1 '000u > GigaBytes
AllocationSize< 1 '000u > KiloBytes
AllocationSize< 1 '024u > KibiBytes
AllocationSize< 1 '000u *1 '000u > MegaBytes