QuakeForge  0.7.2.210-815cf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Defspace handling

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_tdefspace_new (ds_type_t type)
 Create an empty defspace. More...
 

Detailed Description

Typedef Documentation

typedef struct defspace_s defspace_t

Represent a block of memory in the progs data space.

Enumeration Type Documentation

enum ds_type_t
Enumerator
ds_backed 

data space is globally addressable (near/far/type) and has backing store

ds_virtual 

data space has no backing store (local vars, entity fields)

Function Documentation

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().

Parameters
spaceThe space to which the data will be added.
dataThe data to be copied into the space.
sizeThe number of words of data to be copied.
Returns
The offset of the block allocated for the data.
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.

Parameters
spaceThe space from which to allocate data.
sizeThe amount of pr_type_t words to allocated. int and float need 1 word, vector 3 words, and quaternion 4.
Returns
The offset of the first word of the freshly allocated space. May be 0 if the allocated space is at the beginning of the defspace.
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.

Parameters
spaceThe space to which the freed block will be returned.
ofsThe first word of the block to be freed.
sizeThe 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().

Parameters
typeThe 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
Returns
The new, empty defspace.