type sharedMem … type sharedMemHeader … // sharedMemSize returns the size needed for a shared memory buffer that can // contain values of the given size. func sharedMemSize(valueSize int) int { … } // sharedMemTempFile creates a new temporary file of the given size, then maps // it into memory. The file will be removed when the Close method is called. func sharedMemTempFile(size int) (m *sharedMem, err error) { … } // header returns a pointer to metadata within the shared memory region. func (m *sharedMem) header() *sharedMemHeader { … } // valueRef returns the value currently stored in shared memory. The returned // slice points to shared memory; it is not a copy. func (m *sharedMem) valueRef() []byte { … } // valueCopy returns a copy of the value stored in shared memory. func (m *sharedMem) valueCopy() []byte { … } // setValue copies the data in b into the shared memory buffer and sets // the length. len(b) must be less than or equal to the capacity of the buffer // (as returned by cap(m.value())). func (m *sharedMem) setValue(b []byte) { … } // setValueLen sets the length of the shared memory buffer returned by valueRef // to n, which may be at most the cap of that slice. // // Note that we can only store the length in the shared memory header. The full // slice header contains a pointer, which is likely only valid for one process, // since each process can map shared memory at a different virtual address. func (m *sharedMem) setValueLen(n int) { … }