RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

Memory Management Functions

This section details the functions that facilitate memory management.

Typedefs

typedef char* R_CDECL R_MEM_MALLOC_FUNCTION_T (size_t num)
 Allocates memory. More...

typedef char* R_CDECL R_MEM_REALLOC_FUNCTION_T (char *addr, size_t num_new, size_t num_old)
 Reallocates memory. More...

typedef void R_CDECL R_MEM_FREE_FUNCTION_T (char *str)
 Frees memory. More...


Functions

void * Malloc (size_t len)
 Allocates a block of memory. More...

void * Realloc (void *a, size_t new_num, size_t old_num)
 Changes the size of a block of allocated memory. More...

void Free (void *addr)
 Deallocates memory. More...

void R_set_mem_functions (R_MEM_MALLOC_FUNCTION_T *malloc_function, R_MEM_REALLOC_FUNCTION_T *realloc_function, R_MEM_FREE_FUNCTION_T *free_function)
 Sets a user-defined implementation instead of the default implementations for library level memory allocation for R_malloc(), R_realloc() and R_free(). More...

 R_get_mem_functions (R_MEM_MALLOC_FUNCTION_T **malloc_function, R_MEM_REALLOC_FUNCTION_T **realloc_function, R_MEM_FREE_FUNCTION_T **free_function)
 Returns the current implementation for library level memory allocation for R_malloc(), R_realloc() and R_free(). More...

char* R_CDECL R_malloc (size_t num)
 Performs the library level memory allocation. More...

void R_CDECL R_free (char *str)
 Frees library level memory for the memory address str that was allocated via R_malloc(). More...

char* R_CDECL R_realloc (char *addr, size_t num_new, size_t num_old)
 Reallocates library level memory for the memory address str that was allocated via R_malloc() or R_realloc(). More...

char* R_CDECL R_remalloc (char *addr, size_t num)
 Frees an existing pointer and then reallocates library level memory for the memory address addr. More...

void R_malloc_init ()
 Initializes the memory management method functions. More...


Typedef Documentation

typedef void R_CDECL R_MEM_FREE_FUNCTION_T(char *str)
 

Frees memory.

Parameters:
str [In] A reference to the data to deallocate.
See also:
R_set_mem_functions() and R_get_mem_functions().

typedef char* R_CDECL R_MEM_MALLOC_FUNCTION_T(size_t num)
 

Allocates memory.

Parameters:
num [In] The size of memory to allocate.
Returns:
A pointer to allocated memory.
NULL indicates error.
See also:
R_set_mem_functions() and R_get_mem_functions().

typedef char* R_CDECL R_MEM_REALLOC_FUNCTION_T(char *addr, size_t num_new, size_t num_old)
 

Reallocates memory.

Parameters:
addr [In, Out] A reference to the allocated data to resize.
num_new [In] The size of memory to allocate.
num_old [In] The size of memory allocated to addr.
Returns:
Pointer to reallocated memory on success.
Otherwise NULL on error.
See also:
R_set_mem_functions() and R_get_mem_functions().


Function Documentation

void Free void *    addr ;
 

Deallocates memory.

Parameters:
addr [In] The address of memory to deallocate.
See also:
Malloc() and Realloc().
Samples:
app_cache.c, cert.c, cm.c, cm_adv.c, cm_dgst.c, cm_env_strm.c, cm_env_strm_membio.c, cm_open.c, cm_sign_dgst.c, cm_sign_strm.c, cm_smpl.c, cm_strm.c, cm_type.c, cm_vfy_strm_cb.c, evpkey2rpkey.c, ext.c, ocsp_req_create.c, ocsp_req_print.c, ocsp_resp_ext.c, ocsp_resp_find_key.c, ocsp_resp_print.c, ocsp_resp_vfy.c, r_asym.c, r_gnrt.c, r_random.c, r_sign.c, rcert2sslcert.c, reqgen.c, s_crl_check.c, s_crl_verify.c, sock_server.c, sslcert2rcert.c, and vfy_adv.c.

void * Malloc size_t    len ;
 

Allocates a block of memory.

Parameters:
len [In] The size of memory to allocate.
Returns:
A pointer to allocated memory.
NULL indicates error.
See also:
Realloc() and Free().
Samples:
app_cache.c, cert.c, cm_adv.c, cm_dgst.c, cm_env_strm.c, cm_env_strm_membio.c, cm_open.c, cm_sign_dgst.c, cm_sign_strm.c, cm_strm.c, cm_vfy_strm_cb.c, evpkey2rpkey.c, ext.c, ocsp_req_create.c, ocsp_resp_ext.c, ocsp_resp_find_key.c, r_asym.c, r_gnrt.c, r_random.c, r_sign.c, rcert2sslcert.c, reqgen.c, sslcert2rcert.c, and vfy_adv.c.

void R_CDECL R_free char *    str ;
 

Frees library level memory for the memory address str that was allocated via R_malloc().

Parameters:
str [In] A pointer to the memory location.
See also:
R_malloc().

R_get_mem_functions R_MEM_MALLOC_FUNCTION_T **    malloc_function,
R_MEM_REALLOC_FUNCTION_T **    realloc_function,
R_MEM_FREE_FUNCTION_T **    free_function
;
 

Returns the current implementation for library level memory allocation for R_malloc(), R_realloc() and R_free().

Parameters:
malloc_function [Out] The malloc callback function reference.
realloc_function [Out] The realloc callback function reference.
free_function [Out] The free callback function reference.
See also:
R_set_mem_functions(), R_malloc(), R_realloc() and R_free().

char* R_CDECL R_malloc size_t    num ;
 

Performs the library level memory allocation. The active implementation of the memory allocation code is set via R_set_mem_functions() before allocating memory.

Parameters:
num [In] The size of memory to allocate in Bytes.
Returns:
A pointer to the memory location.
See also:
R_set_mem_functions().

void R_malloc_init   ;
 

Initializes the memory management method functions.

note.gif
When working with the library built as a WIN32 DLL, the application's libc memory allocation routines are required as it may have been compiled and linked with different flags. Calling R_malloc_init() performs this, and has no effect on the behavior in standard builds which are already using the allocation routines.
See also:
R_set_mem_functions().

char* R_CDECL R_realloc char *    str,
size_t    num_new,
size_t    num_old
;
 

Reallocates library level memory for the memory address str that was allocated via R_malloc() or R_realloc().

Parameters:
str [In] A pointer to the memory location.
num_new [In] The size in Bytes to reallocate.
num_old [In] The previous amount of allocated memory.
Returns:
A pointer to the memory location.
See also:
R_malloc().

char* R_CDECL R_remalloc char *    addr,
size_t    num
;
 

Frees an existing pointer and then reallocates library level memory for the memory address addr.

Parameters:
addr [In, Out] A pointer to the memory location.
num [In] The size of memory to reallocate in Bytes.
Returns:
A pointer to the memory location.
note.gif
Unlike R_realloc() the data from the existing allocation is not guaranteed to remain.
See also:
R_malloc().

void R_set_mem_functions R_MEM_MALLOC_FUNCTION_T   malloc_function,
R_MEM_REALLOC_FUNCTION_T   realloc_function,
R_MEM_FREE_FUNCTION_T   free_function
;
 

Sets a user-defined implementation instead of the default implementations for library level memory allocation for R_malloc(), R_realloc() and R_free().

Parameters:
malloc_function [In] The malloc callback function.
realloc_function [In] The realloc callback function.
free_function [In] The free callback function.
See also:
R_get_mem_functions().
Samples:
simple.c.

void * Realloc void *    a,
size_t    new_num,
size_t    old_num
;
 

Changes the size of a block of allocated memory.

Parameters:
a [In] The address of memory to reallocate.
new_num [In] The new size of the allocated memory.
old_num [In] The old size of the allocated memory.
Returns:
A pointer to reallocated memory.
NULL indicates error.
See also:
Malloc().


Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1