br_actor
74
is a good example in the way it may allocate default, type specific data.
Generally, you will not need to explicitly free resource blocks allocated by BRender, even if you overwrite pointers to them, as a separate record is maintained of their existence and what they are attached to. This ensures that when something is freed that any resource blocks attached to it are also freed. The only time attached resources need to be freed sooner is if memory is very limited and there is a disproportionately high turnover of allocations of a dependant compared to its parent's lifetime. In such cases BrResFree()
51 can be used (with caution) to free the dependent immediately, e.g. destroying unwanted models loaded using
BrFmtASCLoad()
244.
For simple applications the simple memory allocation functions can be used (see BrMemAllocate()
55), and where structured allocation is required, resource blocks can be allocated from the
BR_MEMORY_APPLICATION
resource class. For more advanced applications requiring greater control, new resource classes can be created (see br_resource_class
324).
There are other features of resource blocks, including the ability to have a call-back function called for each resource block of a particular class.
You will find BrResStrDup()
49
quite useful for specifying identifiers of various data structures.
A pointer to a parental resource block, or
Size of block in bytes.
Resource class (See Memory Management, page 53).
Returns a pointer to the allocated resource block (of at least
A non-
A non-
Returns a pointer to the child resource block.
A pointer to a parental resource block (or
A non-
Returns a pointer to the allocated resource block.
A non-
Returns the resource class.
A non-
Returns the size of the resource block in bytes (may not necessarily be the same as that specified upon allocation, but will not be less).
A non-
A non-
An optional argument to pass to the call-back function.
Returns the first non-zero call-back return value, or zero if all children are enumerated.
A non-
Returns a pointer to the removed resource block.
A pointer to a resource block (previously allocated using
Description:
Allocate a new resource block of a given class.BrResAllocate()
void* BrResAllocate(void* vparent, br_size_t size, int res_class)
void * vparent
Null
if it will have no parent.br_size_t size
int res_class
void *
size
bytes).
Description:
Add a resource block as a dependant or child of another.BrResAdd()
void* BrResAdd(void* vparent, void* vres)
void * vparent
Null
pointer to the parent resource block.void * vres
Null
pointer to the child resource block (will be removed from any current parent).void *
Description:
Duplicate a string.BrResStrDup()
char* BrResStrDup(void* vparent, const char* str)
void * vparent
Null
if independent).const char * str
Null
pointer to the source string.BR_MEMORY_STRING
resource class) and copies a string into it.char *
Description:
Determine the class of a given resource block.BrResClass()
br_uint_8 BrResClass(void* vres)
void * vres
Null
pointer to a resource block.br_uint_8
Description:
Determine the size of a given resource block.BrResSize()
br_uint_32 BrResSize(void* vres)
void * vres
Null
pointer to a resource block.br_uint_32
Description:
Enumerate through all dependant resource blocks of a particular resource block.BrResChildEnum()
br_uint_32 BrResChildEnum(void* vres, br_resenum_cbfn* callback, void* arg)
void * vres
Null
pointer to a resource block.br_resenum_cbfn * callback
Null
pointer to a call-back function.void * arg
arg
) supplied by the user. The call-back itself returns a br_uint_32
348 value. The enumeration will halt at any stage if the return value is non-zero.
br_uint_32
br_uint_32 example_callback(void *vres, void *arg)
{br_uint_32 value;
...
return(value);
}
{ br_uint_32 ev;
void *rblock;
...
ev = BrResChildEnum(rblock,&example_callback,NULL);
}
Description:
Remove a resource block from a parent.BrResRemove()
void* BrResRemove(void* vres)
void * vres
Null
pointer to the resource block to be removed.void *
Null
as its parent.
Description:
Free a resource block.BrResFree()
void BrResFree(void* vres)
void * vres
BrResAllocate()
48BrResStrDup()
49br_resource_class
324), they are invoked when appropriate.
void BR_CALLBACK example_destructor(void* res, br_uint_8 res_class, br_size_t size)
{
...
}
#define EXAMPLE_CLASS (BR_MEMORY_APPLICATION + 1)
static br_resource_class example={"My Class",EXAMPLE_CLASS,example_destructor};
{ BrResClassAdd(&example); /* Create resource class */
...
{ void *ptr;
ptr = BrResAllocate(NULL,1024,EXAMPLE_CLASS);
...
BrResFree(ptr); /* Destructor is invoked */
}
}
See Also:
BrResClassAdd()
325
Generated with CERN WebMaker