Macro libyml::yaml_malloc
source · macro_rules! yaml_malloc { ($t:ty, $size:expr) => { ... }; }
Expand description
Allocates memory using the system’s malloc
function.
This macro wraps the yaml_malloc
function, providing a more Rust-like interface.
§Arguments
size
- The number of bytes to allocate.
§Returns
Returns a *mut T
pointer to the allocated memory, or None
if the allocation failed.
§Safety
While this macro provides a safer interface than direct use of yaml_malloc
,
it is still unsafe because:
- It allocates uninitialized memory.
- The caller is responsible for properly freeing the allocated memory using
yaml_free!
. - The caller must ensure the allocated memory is properly initialized before use.
§Examples
use libyml::{yaml_malloc,yaml_free};
let size = 1024;
unsafe {
if let Some(ptr) = yaml_malloc!(u8, size) {
// Use the allocated memory
// ...
yaml_free!(ptr);
}
}