[−][src]Struct memur::Arena
Arena
is a memory block container that executes drop
for your objects when it goes out of scope.
It can not be used between threads. Create a separate Arena
for each thread.
You can use this Arena
to upload data to memory and receive a pointer to this data.
Behind the scenes, the Arena
will bump the pointer inside the current block, copy
your structure into that location, and return this pointer back. If the Arena
runs out of blocks,
it will request new blocks from the main Memory
.
You should keep a WeakArena
reference together with your pointer, and check if it is_alive
before every pointer access. As long as you have a copy of WeakArena
, the memory won't be
deallocated, however if the Arena
is dropped and you have uploaded the structure with _auto_drop
function, the structure is dropped as well and should not be used.
Arena
and WeakArena
are not intended to be used directly, instead, you should create
wrappers around them for your structures. Inspect List
, UStr
or N
structures for the example code.
You will find that these structures do not keep Arena
inside, because doing that would produce
scenario where the Arena
is never dropped when the structures are nested.
When all WeakArena
and Arena
instances are gone, the memory blocks are returned back to Memory
.
Implementations
impl Arena
[src]
pub fn new(memory: &Memory) -> Result<Arena, UploadError>
[src]
pub unsafe fn upload_auto_drop<T>(
&self,
value: T
) -> Result<(*mut T, *const Option<DropItem>), UploadError>
[src]
&self,
value: T
) -> Result<(*mut T, *const Option<DropItem>), UploadError>
Place item to arena and return a pointer to it, and also add drop function to drop list to drop this
item when there are no remaining Arena
instances. Result also contains a pointer to drop item that is valid while arena is alive.
pub unsafe fn upload_no_drop<T>(&self, value: T) -> Result<*mut T, UploadError>
[src]
Place item to arena and return a pointer to it, without adding a drop function.
pub unsafe fn upload_no_drop_bytes(
&self,
len: usize,
value: impl Iterator<Item = u8>
) -> Result<*mut u8, UploadError>
[src]
&self,
len: usize,
value: impl Iterator<Item = u8>
) -> Result<*mut u8, UploadError>
Place a chunk of bytes to arena and return a pointer to the first byte.
pub unsafe fn alloc_no_drop_items_aligned_uninit<T>(
&self,
len: usize,
offset_between_items: usize
) -> Result<*mut T, UploadError>
[src]
&self,
len: usize,
offset_between_items: usize
) -> Result<*mut T, UploadError>
Place uninitialized items to arena and return a pointer to the first item. This ensures the alignment of the first item.
pub unsafe fn push_custom_drop_fn(
&self,
fun: DropFn,
data: *const u8
) -> Result<*const Option<DropItem>, UploadError>
[src]
&self,
fun: DropFn,
data: *const u8
) -> Result<*const Option<DropItem>, UploadError>
Place custom drop function that will be executed on arena drop.
The data pointer should point to a memory location inside the arena.
pub fn to_weak_arena(&self) -> WeakArena
[src]
Clone as WeakArena
.
Trait Implementations
impl Clone for Arena
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Drop for Arena
[src]
Auto Trait Implementations
impl RefUnwindSafe for Arena
impl !Send for Arena
impl !Sync for Arena
impl Unpin for Arena
impl UnwindSafe for Arena
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,