[][src]Macro malloc_array::heap

macro_rules! heap {
    () => { ... };
    (@) => { ... };
    (@ $x:tt $($xs:tt)* ) => { ... };
    (unsafe $($xs:tt)*) => { ... };
    ($type:ty; $number:expr) => { ... };
    ($value:expr; $number:expr) => { ... };
    ($($n:expr),*) => { ... };
}

vec![]-like macro for creating HeapArray<T> instances.

Provides methods for creating safely accessable arrays using malloc() with a Vec<T> like interface. Also provides methods of optimising deallocations.

Usage

Works like array definitions [type; size], and like the vec![] macro [value; size]. Prepend the statement with unsafe ([unsafe type|value; size]) to prevent potentially redundant drop() calls.

Examples

 use malloc_array::{heap, HeapArray};
 let ints = heap![unsafe 4u32; 32]; // Creates a 32 element `u32` array with each element set to `4`.
 let ints = heap![unsafe u32; 32]; // Creates an uninitialised 32 element `u32` array.
 let ints = heap![u32; 32]; // Same as above, except when `ints` is dropped, each element will be also dropped redundantly.
 let strings = heap!["string one".to_owned(), "string two".to_owned()]; //Creates a 2 element string array.
 let strings = heap![unsafe "memory".to_owned(), "leak".to_owned()]; //Same as above, except `drop()` will not be called on the 2 strings, potentially causing a memory leak.
 let strings: HeapArray<u8> = heap![]; //Creates an empty `u8` array.