Function libyml::memory::yaml_malloc

source ·
pub unsafe fn yaml_malloc(size: u64) -> *mut c_void
Expand description

Allocate memory using the system’s malloc function.

This function allocates size bytes of uninitialized memory and returns a pointer to it.

§Arguments

  • size - The number of bytes to allocate.

§Returns

Returns a pointer to the allocated memory, or a null pointer if the allocation failed.

§Safety

This function is unsafe because:

  • It directly calls the system’s malloc function, which is not memory-safe.
  • The caller must ensure that the allocated memory is properly freed using yaml_free.
  • The caller is responsible for initializing the allocated memory before use.

§Examples

use libyml::memory::yaml_malloc;
use libyml::yaml::size_t;
use libyml::memory::yaml_free;

unsafe {
    let size: size_t = 1024;
    let ptr = yaml_malloc(size);
    if !ptr.is_null() {
        // Use the allocated memory
        // ...
        yaml_free(ptr);
    }
}