objc

Functions
Memory Management

Functions for managing and manipulating memory. More...

Collaboration diagram for Memory Management:

Functions

void * sys_malloc (size_t size)
 Allocates a block of memory. More...
 
void sys_free (void *ptr)
 Frees a block of memory. More...
 
void * sys_memset (void *ptr, uint8_t value, size_t size)
 Set memory to a specific value. More...
 
void * sys_memcpy (void *dest, const void *src, size_t size)
 Copy memory from source to destination. More...
 
void * sys_memmove (void *dest, const void *src, size_t size)
 Move memory from source to destination (handles overlapping regions) More...
 
int sys_memcmp (const void *ptr1, const void *ptr2, size_t num)
 Compare two memory blocks. More...
 
int sys_strcmp (const char *str1, const char *str2)
 Compare two NULL-terminated strings. More...
 

Detailed Description

Functions for managing and manipulating memory.

These are utility functions for memory allocation, deallocation, and manipulation. They provide a simple interface for dynamic memory management, including allocation, freeing, setting, copying, moving, and comparing memory blocks.

In general your target platform will also provide its own memory management functions, but these are provided for convenience and consistency across platforms, in case some platforms do not provide their own versions.

Function Documentation

◆ sys_free()

void sys_free ( void *  ptr)

Frees a block of memory.

Parameters
ptrA pointer to the memory block to be deallocated.
Examples:
examples/runtime/gpio/main.c, and examples/runtime/infrared/main.c.

◆ sys_malloc()

void* sys_malloc ( size_t  size)

Allocates a block of memory.

Parameters
sizeThe number of bytes to allocate.
Returns
A pointer to the allocated memory, or NULL if the allocation fails.
Examples:
examples/runtime/gpio/main.c, and examples/runtime/infrared/main.c.

◆ sys_memcmp()

int sys_memcmp ( const void *  ptr1,
const void *  ptr2,
size_t  num 
)

Compare two memory blocks.

Parameters
ptr1First memory block
ptr2Second memory block
numNumber of bytes to compare
Returns
0 if equal, negative if ptr1 < ptr2, positive if ptr1 > ptr2

◆ sys_memcpy()

void* sys_memcpy ( void *  dest,
const void *  src,
size_t  size 
)

Copy memory from source to destination.

Parameters
destDestination memory block
srcSource memory block
sizeNumber of bytes to copy
Returns
Pointer to destination, or NULL on error

◆ sys_memmove()

void* sys_memmove ( void *  dest,
const void *  src,
size_t  size 
)

Move memory from source to destination (handles overlapping regions)

Parameters
destDestination memory block
srcSource memory block
sizeNumber of bytes to move
Returns
Pointer to destination, or NULL on error

◆ sys_memset()

void* sys_memset ( void *  ptr,
uint8_t  value,
size_t  size 
)

Set memory to a specific value.

Parameters
ptrPointer to the memory block
valueValue to set each byte to
sizeNumber of bytes to set
Returns
Pointer to the memory block, or NULL on error

◆ sys_strcmp()

int sys_strcmp ( const char *  str1,
const char *  str2 
)

Compare two NULL-terminated strings.

Parameters
ptr1First string
ptr2Second string
Returns
0 if equal, negative if ptr1 < ptr2, positive if ptr1 > ptr2