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_ = {};
139inline namespace allocation_size_literals {
142constexpr Bytes operator""_bytes(
unsigned long long int size) {
147constexpr KiloBytes operator""_kb(
unsigned long long int size) {
152constexpr MegaBytes operator""_mb(
unsigned long long int size) {
157constexpr GigaBytes operator""_gb(
unsigned long long int size) {
162constexpr KibiBytes operator""_kib(
unsigned long long int size) {
167constexpr MebiBytes operator""_mib(
unsigned long long int size) {
172constexpr 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
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