Trait malloc_bind::LayoutFinder [] [src]

pub trait LayoutFinder {
    fn get_layout(&self, ptr: *mut u8) -> Layout;

    fn insert_layout(&self, _ptr: *mut u8, _layout: Layout) { ... }
fn delete_layout(&self, _ptr: *mut u8) { ... } }

A mechanism for mapping allocated objects to their Layouts.

A LayoutFinder is an object that can store and look up the Layout associated with an allocated object. In the functions generated by this crate, newly-allocated objects will be inserted into a global LayoutFinder object, and this LayoutFinder will be used to look up the Layouts associated with objects passed to free and other functions.

Required Methods

Get the Layout associated with an allocated object.

get_layout is passed a pointer to an allocated object, and it returns a Layout describing that object. ptr is guaranteed to be an object previously allocated using one of the various C allocation functions.

Provided Methods

Insert a new object to Layout mapping.

insert_layout is passed a pointer to a newly-allocated object and a Layout describing that object, and it stores this mapping. insert_layout is called immediately after allocation in all of the C allocation functions.

The default implementation of insert_layout is a no-op, as some allocators may already keep track of the information necessary to implement get_layout internally.

Delete an existing object to Layout mapping.

delete_layout is passed a pointer to an object whose mapping has previously been inserted, and it deletes this mapping. delete_layout is called immediately after deallocation in all of the C deallocation functions.

The default implementation of delete_layout is a no-op, as some allocators may already keep track of the information necessary to implement get_layout internally.

Implementors