Ring1_Memory_recomputeSize
Recompute the size of a memory block.
Ring1_Result
Ring1_Memory_recomputeSize_suffix
(
type *result,
type min,
type max,
type old,
type additional,
type saturate
)
The following table denotes the valid combinations of suffix and type
suffix |
type |
u8 |
uint8_t |
u16 |
uint16_t |
u32 |
uint32_t |
u64 |
uint64_t |
s8 |
int8_t |
s16 |
int16_t |
s32 |
int32_t |
s64 |
int64_t |
sz |
size_t |
This function computes a new size for a memory block given its old size and a minimum increase in size. This new size is greater than or equal to the minimum increase in size.
This algorithm runs under the assumption that memory blocks are used as dynamic arrays. The goal here is to balance the number of growth operations with the growth per growth operation.
Parameter variables
result
- A pointer to a
type
variable. min
- The minimal value to compute.
max
- The maximal value to compute.
old
- The old value.
additional
- The additional size.
saturate
- Wether saturation should be performed or not.
Return Values
Ring1_Result_Success
on success, Ring1_Result_Failure
on failure.
Post Conditions
If this function fails, then it sets the by-thread status variable.
Below is a list of failure conditions and the status codes indicating them.
Ring1_Status_InvalidArgument
-
if any of the following conditions is true
result
was0
min > max
old < min
old > max
min
is negativeadditional
is negative
Ring1_Status_NotExists
- if the value is not representable by
type
values
If this function fails, result
is not dereferenced.
If this function succeeds, *result
is assigned a value which is computed as follows:
- If
saturate
isfalse
compute the least value \(x\) such that- \(x \ge old + new\)
- \(min \le x \le max\)
- \(x\) is a power of two.
- If
saturate
istrue
compute the least value \(x\) such that- \(x \ge old + new\)
- \(min \le x \le max\)
- \(x\) is a power of two or \(x = max\).