pub unsafe fn dealloc_for_layout(ptr: PtrMut, layout: Layout)Expand description
Deallocates memory for a layout, correctly handling zero-sized types.
For ZSTs (zero-sized types), this is a no-op since no memory was actually
allocated. This avoids undefined behavior since alloc::alloc::dealloc
with a zero-sized layout is UB.
§Safety
- For non-ZST layouts,
ptrmust have been allocated byalloc_for_layout(oralloc::alloc::alloc) with the same layout. ptrmust not have been deallocated already.- For ZST layouts,
ptris ignored (should be the dangling pointer fromalloc_for_layout, but this isn’t checked).