pub struct Arena<'a> {
mem: &'a mut MemoryMapping,
block_size: usize,
regions: RefCell<RegionManager>,
mappings: RefCell<Vec<FileMappingInfo>>,
}
Expand description
Memory arena backed by base::MemoryMapping
.
This struct takes a mutable referencet to the memory mapping so this arena won’t arena the region.
Fields§
§mem: &'a mut MemoryMapping
§block_size: usize
§regions: RefCell<RegionManager>
A set of regions that are not overlapping each other.
Use RefCell
for interior mutability because the mutablity of RegionManager
should be
independent from the mutability of the memory mapping.
mappings: RefCell<Vec<FileMappingInfo>>
Implementations§
source§impl<'a> Arena<'a>
impl<'a> Arena<'a>
sourcepub fn new(block_size: usize, mem: &'a mut MemoryMapping) -> Result<Self>
pub fn new(block_size: usize, mem: &'a mut MemoryMapping) -> Result<Self>
Create a new arena backed by len
bytes of base::MemoryMapping
.
sourcefn reserve(&self, mem_offset: usize, len: usize) -> Result<()>
fn reserve(&self, mem_offset: usize, len: usize) -> Result<()>
A helper function to mark a region as reserved.
sourcepub fn reserve_for_mmap(
&self,
mem_offset: usize,
length: usize,
file: File,
file_offset: usize
) -> Result<()>
pub fn reserve_for_mmap( &self, mem_offset: usize, length: usize, file: File, file_offset: usize ) -> Result<()>
Reserves a region for mmap and stores the mmap information.
Note that Arena
will not call mmap(). Instead, the owner of Arena
instance must call
into_mapping_info()
to retrieve the mapping information and call mmap later instead.
sourcepub fn allocate_slice(
&self,
block: BlockId,
block_offset: usize,
len: usize
) -> Result<&'a mut [u8]>
pub fn allocate_slice( &self, block: BlockId, block_offset: usize, len: usize ) -> Result<&'a mut [u8]>
Allocate a new slice on an anonymous memory.
Arena
structs guarantees that this area is not overlapping with other regions.
sourcepub fn allocate<T: AsBytes + FromBytes + Sized>(
&self,
block: BlockId,
block_offset: usize
) -> Result<&'a mut T>
pub fn allocate<T: AsBytes + FromBytes + Sized>( &self, block: BlockId, block_offset: usize ) -> Result<&'a mut T>
Allocate a new region for a value with type T
.
pub fn write_to_mem<T: AsBytes + FromBytes + Sized>( &self, block_id: BlockId, block_offset: usize, value: &T ) -> Result<()>
sourcepub fn into_mapping_info(self) -> Vec<FileMappingInfo>
pub fn into_mapping_info(self) -> Vec<FileMappingInfo>
Consumes Arena
and retrieve mmap information.