regify utility  2.0.0-0
Memory Management

Abstracted functions pertaining to memory managment. More...

Macros

#define ruFree(p)   ruMacStart { if(p) { free((void*)p); p = NULL; } } ruMacEnd
 Frees given resource and sets paramater to NULL. More...
 
#define ruReplace(p, n)   ruMacStart { if(p) { free((void*)p); } p = n; } ruMacEnd
 Frees given resource and set paramater to new value. More...
 
#define ruMalloc0(count, ctype)   (ctype*) ruMallocSize((rusize)(count), sizeof(ctype));
 Allocate and zero requested memory. More...
 
#define ruRealloc(buf, count, ctype)   (ctype*) ruReallocSize(buf, count, sizeof(ctype))
 Reallocate requested memory without zeroing. More...
 

Typedefs

typedef ptr(* ruClearFunc) (ptr o)
 Signature of a generic free function returning NULL. More...
 
typedef void(* ruFreeFunc) (ptr o)
 Signature of a generic free function. More...
 

Functions

RUAPI ptr ruClear (ptr o)
 Frees given resource if set and returns NULL. More...
 
RUAPI alloc_ptr ruMallocSize (rusize count, rusize ofsize)
 Allocate and zero requested memory. More...
 
RUAPI alloc_ptr ruReallocSize (alloc_ptr buf, rusize count, rusize ofsize)
 Reallocate requested memory without zeroing. More...
 
RUAPI alloc_ptr ruMemDup (trans_ptr buf, rusize size)
 Returns a copy of the given memory block. More...
 

Detailed Description

Abstracted functions pertaining to memory managment.

Macro Definition Documentation

◆ ruFree

#define ruFree (   p)    ruMacStart { if(p) { free((void*)p); p = NULL; } } ruMacEnd

Frees given resource and sets paramater to NULL.

Parameters
presource to be freed and NULLed if not NULL already

◆ ruMalloc0

#define ruMalloc0 (   count,
  ctype 
)    (ctype*) ruMallocSize((rusize)(count), sizeof(ctype));

Allocate and zero requested memory.

Parameters
countNumber of elements to allocate
ctypeThe type of element to allocate. This will be feed to sizeof().
Returns
Guarateed to return the requested memory block casted to (*ctype) or the process will terminate.

◆ ruRealloc

#define ruRealloc (   buf,
  count,
  ctype 
)    (ctype*) ruReallocSize(buf, count, sizeof(ctype))

Reallocate requested memory without zeroing.

Parameters
bufThe initial buffer to extend or reallocated.
countNumber of elements to allocate.
ctypeThe type of element to allocate. This will be feed to sizeof().
Returns
Guarateed to return the requested memory block casted to (*ctype) or the process will terminate.

◆ ruReplace

#define ruReplace (   p,
 
)    ruMacStart { if(p) { free((void*)p); } p = n; } ruMacEnd

Frees given resource and set paramater to new value.

Parameters
presource to be freed before new value is assigned
nnew value to be assigned to freed resource

Typedef Documentation

◆ ruClearFunc

typedef ptr(* ruClearFunc) (ptr o)

Signature of a generic free function returning NULL.

Parameters
oobject to free. Function should insure it's not NULL before freeing

◆ ruFreeFunc

typedef void(* ruFreeFunc) (ptr o)

Signature of a generic free function.

Parameters
oobject to free. Function should insure it's not NULL before freeing

Function Documentation

◆ ruClear()

RUAPI ptr ruClear ( ptr  o)

Frees given resource if set and returns NULL.

Parameters
oresource to be freed and if not NULL already
Returns
NULL

◆ ruMallocSize()

RUAPI alloc_ptr ruMallocSize ( rusize  count,
rusize  ofsize 
)

Allocate and zero requested memory.

Parameters
countNumber of elements to allocate.
ofsizeThe size of each element to allocate.
Returns
Guarateed to return the requested memory block or the process will terminate.

◆ ruMemDup()

RUAPI alloc_ptr ruMemDup ( trans_ptr  buf,
rusize  size 
)

Returns a copy of the given memory block.

Parameters
bufThe memory area to duplicate.
sizenumber of bytes to duplicate.
Returns
Guarateed to return the requested memory block or the process will terminate.

◆ ruReallocSize()

RUAPI alloc_ptr ruReallocSize ( alloc_ptr  buf,
rusize  count,
rusize  ofsize 
)

Reallocate requested memory without zeroing.

Parameters
bufThe initial buffer to extend or reallocated.
countNumber of elements to allocate.
ofsizeThe size of each element to allocate.
Returns
Guarateed to return the requested memory block or the process will terminate.