Skip to main content

SharedMemory

Struct SharedMemory 

Source
pub struct SharedMemory<T: Send + Sync> { /* private fields */ }
Expand description

Static shared memory allocation.

Represents a fixed-size shared memory buffer that is known at compile time. Analogous to __shared__ T data[N] in CUDA.

§Type Parameters

  • T: Element type (must be Send + Sync since shared across threads)

Implementations§

Source§

impl<T: Send + Sync> SharedMemory<T>

Source

pub fn new(count: usize) -> Self

Allocate a new shared memory buffer with count elements, all zeroed.

§Panics

Panics if the allocation fails or if count * size_of::<T>() overflows.

Source

pub fn len(&self) -> usize

Returns the number of elements.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty (always false after construction).

Source

pub fn get(&self, index: usize) -> &T

Get a reference to the element at index.

§Panics

Panics if index >= len.

Source

pub fn get_mut(&mut self, index: usize) -> &mut T

Get a mutable reference to the element at index.

§Safety

The caller must ensure no other thread is reading or writing the same index concurrently (or use appropriate synchronization).

§Panics

Panics if index >= len.

Source

pub fn as_ptr(&self) -> *const T

Get the raw pointer to the underlying buffer.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Get a mutable raw pointer to the underlying buffer.

Source

pub fn as_slice(&self) -> &[T]

Get a slice view of the shared memory.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Get a mutable slice view of the shared memory.

§Safety

Caller must ensure exclusive access.

Trait Implementations§

Source§

impl<T: Send + Sync> Drop for SharedMemory<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send + Sync> Send for SharedMemory<T>

Source§

impl<T: Send + Sync> Sync for SharedMemory<T>

Auto Trait Implementations§

§

impl<T> Freeze for SharedMemory<T>

§

impl<T> RefUnwindSafe for SharedMemory<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for SharedMemory<T>
where T: Unpin,

§

impl<T> UnwindSafe for SharedMemory<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,