\( % Arcus cosine. \def\acos{\cos^{-1}} % Vector projection. \def\projection#1#2{{proj_{#1}\left(#2\right)}} % Vector rejection. \def\rejection#1#2{{rej_{#1}\left(#2\right)}} % Norm. \def\norm#1{{\left\|#1\right\|}} % Cross product. \def\cross#1#2{\mathit{cross}\left(#1,#2\right)} % Dot product. \def\dot#1#2{{#1 \cdot #2}} % Magnitude. \def\mag#1{{\left|#1\right}} \def\group#1{\left(#1\right)}} \def\sbgrp#1{\left\{#1\right\}} \)


Recompute the size of a memory block.

    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

A pointer to a type variable.
The minimal value to compute.
The maximal value to compute.
The old value.
The additional size.
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.


if any of the following conditions is true

  • result was 0
  • min > max
  • old < min
  • old > max
  • min is negative
  • additional is negative
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 is false compute the least value \(x\) such that
    • \(x \ge old + new\)
    • \(min \le x \le max\)
    • \(x\) is a power of two.
  • If saturate is true 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\).