C# Класс SharedMemory.SharedBuffer

Наследование: IDisposable
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
BufferStartPtr byte*
Header SharedHeader*
Mmf MemoryMappedFile
View MemoryMappedViewAccessor
ViewPtr byte*

Открытые методы

Метод Описание
Close ( ) : void

Sets the ShuttingDown flag, and disposes of the MemoryMappedFile and MemoryMappedViewAccessor.
Attempting to read/write to the buffer after closing will result in a System.NullReferenceException.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Защищенные методы

Метод Описание
Dispose ( bool disposeManagedResources ) : void

IDisposable pattern - dispose of managed/unmanaged resources

DoClose ( ) : void

Any classes that inherit from SharedBuffer should implement any Close logic here, Mmf and View are still active at this point. There is no need to call base.DoClose() from these classes.

It is possible for Close to be called before Open has completed successfully, in this situation DoClose should fail gracefully.

DoOpen ( ) : bool

Allows any classes that inherit from SharedBuffer to perform additional open logic. There is no need to call base.DoOpen() from these implementations.

By throwing an exception or returning false, the call to Open will fail and Close will be called.

InitialiseHeader ( ) : void

Initialises the header within the shared memory. Only applicable if IsOwnerOfSharedMemory is true.

Read ( Action readFunc, long bufferPosition ) : void

Prepares an IntPtr to the buffer position and calls readFunc to perform the reading.

Read ( IntPtr destination, int length, long bufferPosition ) : void

Reads length bytes into the memory location destination from the buffer region of the shared memory.

Read ( &data, long bufferPosition ) : void

Reads an instance of T from the buffer

Read ( Array destination, long bufferPosition ) : void

Reads an array of T from the buffer.

ReadArray ( Array destination, int index, int count, long bufferPosition ) : void

Reads a number of elements from a memory location into the provided buffer starting at the specified index.

SharedBuffer ( string name, long bufferSize, bool ownsSharedMemory ) : System

Create a new SharedBuffer instance with the specified name and buffer size

The maximum total shared memory size is dependent upon the system and current memory fragmentation.

The shared memory layout on 32-bit and 64-bit is:
| Header | Buffer |
| 16-bytes | bufferSize |

Write ( Action writeFunc, long bufferPosition ) : void

Prepares an IntPtr to the buffer position and calls writeFunc to perform the writing.

Write ( IntPtr source, int length, long bufferPosition ) : void

Writes length bytes from the source into the shared memory buffer.

Write ( &source, long bufferPosition ) : void

Writes an instance of T into the buffer

Write ( Array source, int index, long bufferPosition ) : void

Writes an array of T into the buffer

Write ( Array source, long bufferPosition ) : void

Writes an array of T into the buffer

WriteArray ( Array source, int index, int count, long bufferPosition ) : void

Writes an array of T into the buffer

Приватные методы

Метод Описание
Open ( ) : bool

Описание методов

Close() публичный Метод

Sets the ShuttingDown flag, and disposes of the MemoryMappedFile and MemoryMappedViewAccessor.
Attempting to read/write to the buffer after closing will result in a System.NullReferenceException.
public Close ( ) : void
Результат void

Dispose() публичный Метод

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

IDisposable pattern - dispose of managed/unmanaged resources
protected Dispose ( bool disposeManagedResources ) : void
disposeManagedResources bool true to dispose of managed resources as well as unmanaged.
Результат void

DoClose() защищенный Метод

Any classes that inherit from SharedBuffer should implement any Close logic here, Mmf and View are still active at this point. There is no need to call base.DoClose() from these classes.
It is possible for Close to be called before Open has completed successfully, in this situation DoClose should fail gracefully.
protected DoClose ( ) : void
Результат void

DoOpen() защищенный Метод

Allows any classes that inherit from SharedBuffer to perform additional open logic. There is no need to call base.DoOpen() from these implementations.
By throwing an exception or returning false, the call to Open will fail and Close will be called.
protected DoOpen ( ) : bool
Результат bool

InitialiseHeader() защищенный Метод

Initialises the header within the shared memory. Only applicable if IsOwnerOfSharedMemory is true.
protected InitialiseHeader ( ) : void
Результат void

Read() защищенный Метод

Prepares an IntPtr to the buffer position and calls readFunc to perform the reading.
protected Read ( Action readFunc, long bufferPosition ) : void
readFunc Action A function used to read from the buffer. The IntPtr parameter is a pointer to the buffer offset by .
bufferPosition long The offset within the buffer region of the shared memory to read from.
Результат void

Read() защищенный Метод

Reads length bytes into the memory location destination from the buffer region of the shared memory.
protected Read ( IntPtr destination, int length, long bufferPosition ) : void
destination IntPtr A managed pointer to the memory location to copy data into from the buffer
length int The number of bytes to be copied
bufferPosition long The offset within the buffer region of the shared memory to read from.
Результат void

Read() защищенный Метод

Reads an instance of T from the buffer
protected Read ( &data, long bufferPosition ) : void
data Output parameter that will contain the value read from the buffer
bufferPosition long The offset within the buffer region of the shared memory to read from.
Результат void

Read() защищенный Метод

Reads an array of T from the buffer.
protected Read ( Array destination, long bufferPosition ) : void
destination Array Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.
bufferPosition long The offset within the buffer region of the shared memory to read from.
Результат void

ReadArray() защищенный Метод

Reads a number of elements from a memory location into the provided buffer starting at the specified index.
protected ReadArray ( Array destination, int index, int count, long bufferPosition ) : void
destination Array The destination buffer.
index int The start index within .
count int The number of elements to read.
bufferPosition long The source offset within the buffer region of the shared memory.
Результат void

SharedBuffer() защищенный Метод

Create a new SharedBuffer instance with the specified name and buffer size

The maximum total shared memory size is dependent upon the system and current memory fragmentation.

The shared memory layout on 32-bit and 64-bit is:
| Header | Buffer |
| 16-bytes | bufferSize |

protected SharedBuffer ( string name, long bufferSize, bool ownsSharedMemory ) : System
name string The name of the shared memory
bufferSize long The buffer size in bytes. The total shared memory size will be Marshal.SizeOf(SharedMemory.SharedHeader) + bufferSize
ownsSharedMemory bool Whether or not the current instance owns the shared memory. If true a new shared memory will be created and initialised otherwise an existing one is opened.
Результат System

Write() защищенный Метод

Prepares an IntPtr to the buffer position and calls writeFunc to perform the writing.
protected Write ( Action writeFunc, long bufferPosition ) : void
writeFunc Action A function used to write to the buffer. The IntPtr parameter is a pointer to the buffer location offset by .
bufferPosition long The offset within the buffer region to start writing to.
Результат void

Write() защищенный Метод

Writes length bytes from the source into the shared memory buffer.
protected Write ( IntPtr source, int length, long bufferPosition ) : void
source IntPtr A managed pointer to the memory location to be copied into the buffer
length int The number of bytes to be copied
bufferPosition long The offset within the buffer region of the shared memory to write to.
Результат void

Write() защищенный Метод

Writes an instance of T into the buffer
protected Write ( &source, long bufferPosition ) : void
source A reference to an instance of to be written into the buffer
bufferPosition long The offset within the buffer region of the shared memory to write to.
Результат void

Write() защищенный Метод

Writes an array of T into the buffer
protected Write ( Array source, int index, long bufferPosition ) : void
source Array An array of to be written. The length of this array controls the number of elements to be written.
index int The index within the array to start writing from.
bufferPosition long The offset within the buffer region of the shared memory to write to.
Результат void

Write() защищенный Метод

Writes an array of T into the buffer
protected Write ( Array source, long bufferPosition ) : void
source Array An array of to be written. The length of this array controls the number of elements to be written.
bufferPosition long The offset within the buffer region of the shared memory to write to.
Результат void

WriteArray() защищенный Метод

Writes an array of T into the buffer
protected WriteArray ( Array source, int index, int count, long bufferPosition ) : void
source Array The source data to be written to the buffer
index int The start index within .
count int The number of elements to write.
bufferPosition long The offset within the buffer region of the shared memory to write to.
Результат void

Описание свойств

BufferStartPtr защищенное свойство

Pointer to the start of the buffer region of the memory mapped view
protected byte* BufferStartPtr
Результат byte*

Header защищенное свойство

Pointer to the header within shared memory
protected SharedHeader* Header
Результат SharedHeader*

Mmf защищенное свойство

Memory mapped file
protected MemoryMappedFile Mmf
Результат MemoryMappedFile

View защищенное свойство

Memory mapped view
protected MemoryMappedViewAccessor View
Результат MemoryMappedViewAccessor

ViewPtr защищенное свойство

Pointer to the memory mapped view
protected byte* ViewPtr
Результат byte*