Data Structures | |
struct | defspace_s |
Represent a block of memory in the progs data space. More... | |
Typedefs | |
typedef struct defspace_s | defspace_t |
Represent a block of memory in the progs data space. More... | |
Enumerations | |
enum | ds_type_t { ds_backed, ds_virtual } |
Functions | |
int | defspace_add_data (defspace_t *space, pr_type_t *data, int size) |
Copy a block of data into a defspace. More... | |
int | defspace_alloc_loc (defspace_t *space, int size) |
Allocate space from the defspace's backing memory. More... | |
void | defspace_free_loc (defspace_t *space, int ofs, int size) |
Free a block of contiguous words, returning them to the defspace. More... | |
defspace_t * | defspace_new (ds_type_t type) |
Create an empty defspace. More... | |
typedef struct defspace_s defspace_t |
Represent a block of memory in the progs data space.
enum ds_type_t |
int defspace_add_data | ( | defspace_t * | space, |
pr_type_t * | data, | ||
int | size | ||
) |
Copy a block of data into a defspace.
Space for the data is allocated from the defspace via defspace_alloc_loc().
If data is null, then the copying stage is skipped and this function because a synonym for defspace_alloc_loc().
space | The space to which the data will be added. |
data | The data to be copied into the space. |
size | The number of words of data to be copied. |
int defspace_alloc_loc | ( | defspace_t * | space, |
int | size | ||
) |
Allocate space from the defspace's backing memory.
If the memory is fragmented, then the first available location at least as large as size is returned. This means that freeing a location then allocating the same amount of space may return a different location.
If memory cannot be allocated (there is no free space in the currently available memory and defspace_t::grow is null), then an internal error will be generated.
space | The space from which to allocate data. |
size | The amount of pr_type_t words to allocated. int and float need 1 word, vector 3 words, and quaternion 4. |
void defspace_free_loc | ( | defspace_t * | space, |
int | ofs, | ||
int | size | ||
) |
Free a block of contiguous words, returning them to the defspace.
The block to be freed is specified by ofs indicating the offset of the first word of the block and size indicating the number of words in the block.
If the block to be freed has 0 words, or if the is partly or fully outside the defspace (as defined by defspace_t::size), or if the block overlaps any unallocated space in the defspace, then an internal error will be generated. However, it is perfectly valid to allocate a large block and subsequently free a small block from anywhere within the larger block. This is because when memory is not fragmented, there is no difference between allocating one large block and allocating several smaller blocks when allocating the same amount of memory.
space | The space to which the freed block will be returned. |
ofs | The first word of the block to be freed. |
size | The number of words in the block to be freed. |
defspace_t* defspace_new | ( | ds_type_t | type | ) |
Create an empty defspace.
No backing memory is allocated, but the defspace_t::grow function is initialized to the default grow function so the backing memory may be accessed after space has been allocated via defspace_alloc_loc().
type | The type of defspace to create. Affects only the default defspace_t::grow function: ds_backed uses a grow function that allocates backing memory, while ds_virtual uses a grow function that only increases defspace_t::max_size |