#[repr(C)]pub struct DynamicBuffer {
pub pointer: *mut u8,
pub length: usize,
pub destructor: Option<unsafe extern "C" fn(*mut u8, usize) -> c_int>,
}Fields§
§pointer: *mut u8§length: usize§destructor: Option<unsafe extern "C" fn(*mut u8, usize) -> c_int>Implementations§
Source§impl DynamicBuffer
impl DynamicBuffer
Sourcepub unsafe fn destroy(&mut self) -> Result<(), &str>
pub unsafe fn destroy(&mut self) -> Result<(), &str>
Destroy the DynamicBuffer freeing the underlying memory using the provided
destructor_callback and clearing or zeroing all the members.
If the pointer stored in DynamicBuffer is NULL, then length is zeroed out and the
destructor_callback is set to None. It is similar to how free ignores NULL in C, we just
do some additional housekeeping to signal the DynamicBuffer is an empty shell.
§Safety
Destroy is safe to call only if the destructor_callback is the method that needs to be
called to free the stored pointer. For example in C++, memory allocated with new must be
freed with delete, memory allocated with new[] must be freed with delete[].
Length must indicate how many u8 are present in the allocation and can be used by the
destructor_callback to free memory. For example in the case of a Vec being turned into a
DynamicBuffer the length is obtained by first calling the len function on the Vec.