Struct base::shm::SharedMemory
source · pub struct SharedMemory {
pub descriptor: SafeDescriptor,
pub size: u64,
}
Expand description
A shared memory file descriptor and its size.
Fields§
§descriptor: SafeDescriptor
§size: u64
Implementations§
sourcepub fn new<T: Into<Vec<u8>>>(debug_name: T, size: u64) -> Result<SharedMemory>
pub fn new<T: Into<Vec<u8>>>(debug_name: T, size: u64) -> Result<SharedMemory>
Creates a new shared memory object of the given size.
|name| is purely for debugging purposes. It does not need to be unique, and it does not affect any non-debugging related properties of the constructed shared memory.
sourcepub fn size(&self) -> u64
pub fn size(&self) -> u64
Gets the size in bytes of the shared memory.
The size returned here does not reflect changes by other interfaces or users of the shared memory file descriptor.
sourcepub fn from_safe_descriptor(
descriptor: SafeDescriptor,
size: u64
) -> Result<SharedMemory>
pub fn from_safe_descriptor( descriptor: SafeDescriptor, size: u64 ) -> Result<SharedMemory>
Creates a SharedMemory instance from a SafeDescriptor owning a reference to a shared memory descriptor. Ownership of the underlying descriptor is transferred to the new SharedMemory object.
sourcepub fn try_clone(&self) -> Result<SharedMemory>
pub fn try_clone(&self) -> Result<SharedMemory>
Clones the SharedMemory. The new SharedMemory will refer to the same underlying object as the original.
Trait Implementations§
USE THIS CAUTIOUSLY. On Windows, the returned handle is not a file handle and cannot be used as if it were one. It is a handle to a the associated file mapping object and should only be used for memory-mapping the file view.
source§fn as_raw_descriptor(&self) -> RawDescriptor
fn as_raw_descriptor(&self) -> RawDescriptor
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§fn from(sm: SharedMemory) -> SafeDescriptor
fn from(sm: SharedMemory) -> SafeDescriptor
source§fn new(debug_name: &CStr, size: u64) -> Result<SharedMemory>
fn new(debug_name: &CStr, size: u64) -> Result<SharedMemory>
Creates a new shared memory file descriptor with the specified size
in bytes.
name
will appear in /proc/self/fd/<shm fd>
for the purposes of debugging. The name does
not need to be unique.
The file descriptor is opened with the close on exec flag and allows memfd sealing.
If the MFD_NOEXEC_SEAL
flag is supported, the resulting file will also be created with a
non-executable file mode (in other words, it cannot be passed to the exec
family of system
calls).
source§fn from_safe_descriptor(
descriptor: SafeDescriptor,
size: u64
) -> Result<SharedMemory>
fn from_safe_descriptor( descriptor: SafeDescriptor, size: u64 ) -> Result<SharedMemory>
Creates a SharedMemory instance from a SafeDescriptor owning a reference to a shared memory descriptor. Ownership of the underlying descriptor is transferred to the new SharedMemory object.