diff --git a/src/mem.rs b/src/mem.rs index a495a44..96fdc75 100644 --- a/src/mem.rs +++ b/src/mem.rs @@ -44,6 +44,11 @@ impl MemoryContext { unsafe { raw::MemoryContextSwitchTo(prev) }; result } + + pub(crate) fn memory_allocated(&self) -> usize { + // SAFETY: `self.0` is always a valid memory context + unsafe { &*self.0 }.mem_allocated + } } // SAFETY: This will never have any parents, so we don't need to worry about diff --git a/src/owned.rs b/src/owned.rs index 761abdc..0f07c0d 100644 --- a/src/owned.rs +++ b/src/owned.rs @@ -6,7 +6,7 @@ use std::ops::Deref; /// An owned version of a node pub struct Owned { /// The memory context the node is allocated onto - _mem: mem::MemoryContext, + mem: mem::MemoryContext, /// A pointer to a node allocated onto [_mem] ptr: *mut raw::Node, _marker: PhantomData, @@ -21,11 +21,15 @@ unsafe impl Sync for Owned {} impl Owned { pub(crate) fn new(mem: mem::MemoryContext, ptr: *mut raw::Node) -> Self { Self { - _mem: mem, + mem, ptr, _marker: PhantomData, } } + + pub fn memory_allocated(&self) -> usize { + self.mem.memory_allocated() + } } impl Deref for Owned