You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: SharedMemory/Array.cs
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ public Array(string name, int length)
87
87
/// Opens an existing shared memory array with the name as specified by <paramref name="name"/>.
88
88
/// </summary>
89
89
/// <param name="name">The name of the shared memory array to open.</param>
90
-
/// <exception cref="ArgumentOutOfRangeException">If the shared memory location specified by <paramref name="name"/> does not have a <see cref="BufferSize"/> that is evenly divisable by the size of <typeparamref name="T"/>.</exception>
90
+
/// <exception cref="ArgumentOutOfRangeException">If the shared memory location specified by <paramref name="name"/> does not have a <see cref="Buffer.BufferSize"/> that is evenly divisable by the size of <typeparamref name="T"/>.</exception>
91
91
publicArray(stringname)
92
92
:base(name,0,false)
93
93
{
@@ -98,9 +98,12 @@ public Array(string name)
98
98
99
99
#endregion
100
100
101
+
/// <summary>
102
+
/// Perform any initialisation required when opening the shared memory array
103
+
/// </summary>
104
+
/// <returns>true if successful</returns>
101
105
protectedoverrideboolDoOpen()
102
106
{
103
-
104
107
if(!IsOwnerOfSharedMemory)
105
108
{
106
109
if(BufferSize%_elementSize!=0)
@@ -131,7 +134,7 @@ public void Write(ref T data, int index)
131
134
/// </summary>
132
135
/// <param name="buffer">The source array to copy elements from.</param>
133
136
/// <param name="startIndex">The zero-based index of the shared memory array element to begin writing to.</param>
134
-
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndex"/> is less than 0 -or- <see cref="buffer.Length"/> + <paramref name="startIndex"/> is greater than <see cref="Length"/>.</exception>
137
+
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndex"/> is less than 0 -or- length of <paramref name="buffer"/> + <paramref name="startIndex"/> is greater than <see cref="Length"/>.</exception>
135
138
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> must not be null</exception>
136
139
publicvoidWrite(T[]buffer,intstartIndex=0)
137
140
{
@@ -167,7 +170,7 @@ public void Read(out T data, int index)
167
170
/// </summary>
168
171
/// <param name="buffer">The destination array to copy the elements into.</param>
169
172
/// <param name="startIndex">The zero-based index of the shared memory array element to begin reading from.</param>
170
-
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndex"/> is less than 0 -or- <see cref="buffer.Length"/> + <paramref name="startIndex"/> is greater than <see cref="Length"/>.</exception>
173
+
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndex"/> is less than 0 -or- length of <paramref name="buffer"/> + <paramref name="startIndex"/> is greater than <see cref="Length"/>.</exception>
171
174
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> must not be null</exception>
/// Create a new or open an existing shared memory buffer with the name of <see cref="Name"/>.
186
+
/// Creates a new or opens an existing shared memory buffer with the name of <see cref="Name"/> depending on the value of <see cref="IsOwnerOfSharedMemory"/>.
172
187
/// </summary>
173
188
/// <returns>True if the memory was successfully mapped</returns>
174
189
/// <remarks>If <see cref="IsOwnerOfSharedMemory"/> is true then the shared memory buffer will be created, opening will fail in this case if the shared memory already exists. Otherwise if IsOwnerOfSharedMemory is false then the shared memory buffer will be opened, which will fail if it doesn't already exist.</remarks>
175
190
/// <exception cref="System.IO.IOException">If trying to create a new shared memory buffer with a duplicate name as buffer owner.</exception>
176
191
/// <exception cref="System.IO.FileNotFoundException">If trying to open a new shared memory buffer that does not exist as a consumer of existing buffer.</exception>
177
192
/// <exception cref="System.ArgumentOutOfRangeException">If trying to create a new shared memory buffer with a size larger than the logical addressable space.</exception>
178
-
publicboolOpen()
193
+
protectedboolOpen()
179
194
{
195
+
Close();
196
+
180
197
try
181
198
{
182
199
// Attempts to create or open the shared memory with a name of this.Name
@@ -325,7 +342,7 @@ protected virtual void Write<T>(ref T data, long bufferPosition = 0)
325
342
/// Writes an array of <typeparamref name="T"/> into the buffer
/// <param name="data">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
345
+
/// <param name="buffer">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
329
346
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to write to.</param>
/// <param name="data">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
394
+
/// <param name="buffer">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
378
395
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to read from.</param>
/// Allow copying memory from one IntPtr to another. Required as the <see cref="Marshal.Copy"/> implementation does not provide an appropriate override.
452
+
/// Allow copying memory from one IntPtr to another. Required as the <see cref="System.Runtime.InteropServices.Marshal.Copy(System.IntPtr, System.IntPtr[], int, int)"/> implementation does not provide an appropriate override.
/// <param name="data">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
83
+
/// <param name="buffer">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
73
84
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to write to.</param>
/// <param name="data">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
132
+
/// <param name="buffer">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
122
133
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to read from.</param>
/// Blocks the current thread until it is able to acquire a read lock. If succesfull all subsequent writes will be blocked until after a call to <paramref name="ReleaseReadLock"/>.
77
+
/// Blocks the current thread until it is able to acquire a read lock. If succesfull all subsequent writes will be blocked until after a call to <see cref="ReleaseReadLock"/>.
78
78
/// </summary>
79
79
/// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.</param>
80
80
/// <returns>true if the read lock was able to be acquired, otherwise false.</returns>
@@ -97,7 +97,7 @@ public void ReleaseReadLock()
97
97
}
98
98
99
99
/// <summary>
100
-
/// Blocks the current thread until it is able to acquire a write lock. If succesfull all subsequent reads will be blocked until after a call to <paramref name="ReleaseWriteLock"/>.
100
+
/// Blocks the current thread until it is able to acquire a write lock. If succesfull all subsequent reads will be blocked until after a call to <see cref="ReleaseWriteLock"/>.
101
101
/// </summary>
102
102
/// <param name="millisecondsTimeout">The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely.</param>
103
103
/// <returns>true if the write lock was able to be acquired, otherwise false.</returns>
@@ -139,7 +139,7 @@ protected override void Write<T>(ref T data, long bufferPosition = 0)
139
139
/// Writes an array of <typeparamref name="T"/> into the buffer
/// <param name="data">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
142
+
/// <param name="buffer">An array of <typeparamref name="T"/> to be written. The length of this array controls the number of elements to be written.</param>
143
143
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to write to.</param>
/// <param name="data">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
193
+
/// <param name="buffer">Array that will contain the values read from the buffer. The length of this array controls the number of elements to read.</param>
194
194
/// <param name="bufferPosition">The offset within the buffer region of the shared memory to read from.</param>
0 commit comments