mjsonrpc 1.0
A lightweight JSON-RPC 2.0 message parser and generator based on cJSON
Loading...
Searching...
No Matches
Typedefs | Functions
Memory Management Hooks

Custom memory management function hooks. More...

Typedefs

typedef void *(* mjrpc_malloc_func) (size_t size)
 Function pointer type for custom memory allocation.
 
typedef void(* mjrpc_free_func) (void *ptr)
 Function pointer type for custom memory deallocation.
 
typedef char *(* mjrpc_strdup_func) (const char *str)
 Function pointer type for custom string duplication.
 

Functions

int mjrpc_set_memory_hooks (mjrpc_malloc_func malloc_func, mjrpc_free_func free_func, mjrpc_strdup_func strdup_func)
 Set custom memory management functions.
 

Detailed Description

Custom memory management function hooks.

Typedef Documentation

◆ mjrpc_free_func

mjrpc_free_func

Function pointer type for custom memory deallocation.

Parameters
ptrPointer to memory to free (can be NULL)
Note
Should behave like standard free() function

Definition at line 215 of file mjsonrpc.h.

◆ mjrpc_malloc_func

mjrpc_malloc_func

Function pointer type for custom memory allocation.

Parameters
sizeNumber of bytes to allocate
Returns
Pointer to allocated memory, or NULL on failure
Note
Should behave like standard malloc() function

Definition at line 205 of file mjsonrpc.h.

◆ mjrpc_strdup_func

mjrpc_strdup_func

Function pointer type for custom string duplication.

Parameters
strString to duplicate
Returns
Pointer to newly allocated duplicate string, or NULL on failure
Note
Should behave like standard strdup() function

Definition at line 226 of file mjsonrpc.h.

Function Documentation

◆ mjrpc_set_memory_hooks()

int mjrpc_set_memory_hooks ( mjrpc_malloc_func  malloc_func,
mjrpc_free_func  free_func,
mjrpc_strdup_func  strdup_func 
)

Set custom memory management functions.

This function allows users to override the default memory management functions used by the mjsonrpc library. All parameters must be provided together, or pass NULL for all to reset to default standard library functions.

Parameters
malloc_funcCustom malloc function (required if not resetting)
free_funcCustom free function (required if not resetting)
strdup_funcCustom strdup function (required if not resetting)
Returns
MJRPC_RET_OK on success, MJRPC_RET_ERROR_INVALID_PARAM on invalid parameters
Note
Call this function before creating any mjrpc_handle or processing requests
To reset to default functions, pass NULL for all parameters
Example:
// Set custom memory functions
mjrpc_set_memory_hooks(my_malloc, my_free, my_strdup);
// Reset to default functions
mjrpc_set_memory_hooks(NULL, NULL, NULL);
int mjrpc_set_memory_hooks(mjrpc_malloc_func malloc_func, mjrpc_free_func free_func, mjrpc_strdup_func strdup_func)
Set custom memory management functions.