Struct shared_memory::SharedMem
[−]
[src]
pub struct SharedMem<'a> { /* fields omitted */ }
Struct used to manipulate the shared memory
Methods
impl<'a> SharedMem<'a>
[src]
pub fn create(
new_link_path: PathBuf,
lock_type: LockType,
size: usize
) -> Result<SharedMem<'a>, Box<Error>>
[src]
new_link_path: PathBuf,
lock_type: LockType,
size: usize
) -> Result<SharedMem<'a>, Box<Error>>
Creates a new SharedMem
This involves creating a "link" on disk specified by the first parameter. This link contains the OS specific identifier to the shared memory. The usage of such link files on disk help manage identifier colisions. (ie: a binary using the same argument to this function can be ran from different directories without worrying about collisions)
Examples
//Creates a new shared SharedMem named shared_mem.link of size 4096 let mut my_shmem: SharedMem = match SharedMem::create(PathBuf::from("shared_mem.link"), LockType::Mutex, 4096) { Ok(v) => v, Err(e) => { println!("Error : {}", e); println!("Failed to create SharedMem..."); return; } };
pub fn open(existing_link_path: PathBuf) -> Result<SharedMem<'a>, Box<Error>>
[src]
Opens an existing SharedMem
This function takes a path to a link file created by create(). Open() will automatically detect the size and locking mechanisms.
Examples
use shared_memory::*; //Opens an existing shared SharedMem named test.txt let mut my_shmem: SharedMem = match SharedMem::open(PathBuf::from("shared_mem.link")) { Ok(v) => v, Err(e) => { println!("Error : {}", e); println!("Failed to open SharedMem..."); return; } };
pub fn create_raw(
shmem_path: String,
size: usize
) -> Result<SharedMem<'a>, Box<Error>>
[src]
shmem_path: String,
size: usize
) -> Result<SharedMem<'a>, Box<Error>>
Creates a raw shared memory object. Only use this method if you do not wish to have all the nice features of a regular SharedMem.
This function is useful when creating mappings for libraries/applications that do not use SharedMem. By using this function, you explicitly mean : do not create anything else than a memory mapping.
The first argument needs to be a valid identifier for the OS in use. colisions wont be avoided through link files and no meta data (locks) is added to the shared mapping.
pub fn open_raw(shmem_path: String) -> Result<SharedMem<'a>, Box<Error>>
[src]
Opens an existing shared memory mappping in raw mode. This simply opens an existing mapping with no additionnal features (no locking, no metadata, etc...).
This function is useful when using mappings not created by my_shmem.
To use this function, you need to pass a valid OS shared memory identifier as an argument.
pub fn get_size(&self) -> &usize
[src]
Returns the size of the SharedMem
pub fn get_link_path(&self) -> Option<&PathBuf>
[src]
Returns the link_path of the SharedMem
pub fn get_real_path(&self) -> Option<&String>
[src]
Returns the OS specific path of the shared memory object
Usualy on Linux, this will point to a file under /dev/shm/
On Windows, this returns a namespace
Trait Implementations
impl<'a> SharedMemLockable for SharedMem<'a>
[src]
fn rlock<D: SharedMemCast>(&self) -> Result<ReadLockGuard<D>, Box<Error>>
[src]
Returns a read lock to the shared memory Read more
fn rlock_as_slice<D: SharedMemCast>(
&self
) -> Result<ReadLockGuardSlice<D>, Box<Error>>
[src]
&self
) -> Result<ReadLockGuardSlice<D>, Box<Error>>
Returns a read lock to the shared memory as a slice Read more
fn wlock<D: SharedMemCast>(&mut self) -> Result<WriteLockGuard<D>, Box<Error>>
[src]
Returns a read/write lock to the shared memory # Examples Read more
fn wlock_as_slice<D: SharedMemCast>(
&mut self
) -> Result<WriteLockGuardSlice<D>, Box<Error>>
[src]
&mut self
) -> Result<WriteLockGuardSlice<D>, Box<Error>>
Returns a read/write access to a &mut [T] on the shared memory Read more