The mozilla::ipc::Shmem
type represents a block of memory that IPDL messages can transfer between processes without having to copy the contents. IPDL messages can pass and Shmem
arguments, as in these examples from PWebGPU.ipdl
:
async BufferReturnShmem(RawId selfId, Shmem shmem);
async BufferMap(RawId selfId, WGPUHostMap hostMap, uint64_t offset, uint64_t size) returns (Shmem sm);
Given a Shmem
s
, you can call s.Size<T>
to get the length of the shared memory block considered as an array of T
values, and s.get<T>
to get a T*
pointing to the first element.
A Shmem
is usually first constructed with no memory allocated to it, using the default constructor. For example, the[Device::CreateBuffer
][cbi] method in Firefox's WebGPU implementation declares a Shmem
like this: