History

GSF.Core: Obsoleted the BufferPool and modified usages to simply instantiate new buffers where necessary.

StephenCWills committed 11 years ago

Commit a88c4951 parent b9dd9b022 files · +561 −944Browse files

Showing the changes to Source/Libraries/GSF.Core/Parsing/MultiSourceFrameImageParserBase.cs (1 of 22 files). Show all

Unified · Split

Source/Libraries/GSF.Core/Parsing/MultiSourceFrameImageParserBase.cs+15−112
@@ -78,17 +78,10 @@ namespace GSF.Parsing · 77 unmodified lines
7878 /// automatic object pool handling, e.g., returning object to pool when disposed.
7979 /// </remarks>
8080 [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
81− public class SourceIdentifiableBuffer : ISupportLifecycle
81+ public class SourceIdentifiableBuffer
8282 {
8383 #region [ Members ]
8484
85− // Events
86−
87− /// <summary>
88− /// Occurs when <see cref="SourceIdentifiableBuffer"/> is disposed.
89− /// </summary>
90− public event EventHandler Disposed;
91−
9285 // Fields
9386
9487 /// <summary>
@@ -102,19 +95,6 @@ namespace GSF.Parsing · 7 unmodified lines
10295 public byte[] Buffer;
10396
10497 private int m_count;
105− private bool m_disposed;
106−
107− #endregion
108−
109− #region [ Constructors ]
110−
111− /// <summary>
112− /// Releases the unmanaged resources before the <see cref="SourceIdentifiableBuffer"/> object is reclaimed by <see cref="GC"/>.
113− /// </summary>
114− ~SourceIdentifiableBuffer()
115− {
116− Dispose(false);
117− }
11898
11999 #endregion
120100
@@ -144,63 +124,7 @@ namespace GSF.Parsing · 23 unmodified lines
144124 set
145125 {
146126 m_count = value;
147−
148− if ((object)Buffer != null)
149− BufferPool.ReturnBuffer(Buffer);
150−
151− if (m_count > 0)
152− Buffer = BufferPool.TakeBuffer(m_count);
153− else
154− Buffer = null;
155− }
156− }
157−
158− #endregion
159−
160− #region [ Methods ]
161−
162− /// <summary>
163− /// Releases all the resources used by the <see cref="SourceIdentifiableBuffer"/> object.
164− /// </summary>
165− public void Dispose()
166− {
167− Dispose(true);
168− GC.SuppressFinalize(this);
169− }
170−
171− /// <summary>
172− /// Releases the unmanaged resources used by the <see cref="SourceIdentifiableBuffer"/> object and optionally releases the managed resources.
173− /// </summary>
174− /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
175− protected virtual void Dispose(bool disposing)
176− {
177− if (!m_disposed)
178− {
179− try
180− {
181− // Return any existing buffer to the pool
182− Count = 0;
183− }
184− finally
185− {
186− m_disposed = true; // Prevent duplicate dispose.
187−
188− if (Disposed != null)
189− Disposed(this, EventArgs.Empty);
190− }
191− }
192− }
193−
194− /// <summary>
195− /// Initializes (or reinitializes) <see cref="SourceIdentifiableBuffer"/> state.
196− /// </summary>
197− public void Initialize()
198− {
199− // Un-dispose class instance if it is being reused
200− if (m_disposed)
201− {
202− m_disposed = false;
203− GC.ReRegisterForFinalize(this);
127+ Buffer = new byte[m_count];
204128 }
205129 }
206130
@@ -323,31 +247,20 @@ namespace GSF.Parsing · 116 unmodified lines
323247
324248 buffer.ValidateParameters(offset, count);
325249
326− try
327− {
328− if (count > 0)
329− {
330− // Get an identifiable buffer object
331− identifiableBuffer = FastObjectFactory<SourceIdentifiableBuffer>.CreateObjectFunction();
332− identifiableBuffer.Source = source;
333− identifiableBuffer.Count = count;
334−
335− // Copy buffer data for processing (destination buffer pre-allocated from buffer pool)
336− Buffer.BlockCopy(buffer, offset, identifiableBuffer.Buffer, 0, count);
337−
338− // Add buffer to the queue for parsing. Note that buffer is queued for parsing instead
339− // of handling parse on this thread - this has become necessary to reduce UDP data loss
340− // that can happen in-process when system has UDP buffers building up for processing.
341− m_bufferQueue.Enqueue(new[] { identifiableBuffer });
342− }
343− }
344− catch
250+ if (count > 0)
345251 {
346− // Properly dispose of the source buffer if we failed to queue it for processing
347− if ((object)identifiableBuffer != null)
348− identifiableBuffer.Dispose();
349−
350− throw;
252+ // Get an identifiable buffer object
253+ identifiableBuffer = FastObjectFactory<SourceIdentifiableBuffer>.CreateObjectFunction();
254+ identifiableBuffer.Source = source;
255+ identifiableBuffer.Count = count;
256+
257+ // Copy buffer data for processing
258+ Buffer.BlockCopy(buffer, offset, identifiableBuffer.Buffer, 0, count);
259+
260+ // Add buffer to the queue for parsing. Note that buffer is queued for parsing instead
261+ // of handling parse on this thread - this has become necessary to reduce UDP data loss
262+ // that can happen in-process when system has UDP buffers building up for processing.
263+ m_bufferQueue.Enqueue(new[] { identifiableBuffer });
351264 }
352265 }
353266
@@ -430,16 +343,6 @@ namespace GSF.Parsing · 76 unmodified lines
430343 }
431344 finally
432345 {
433− // Dispose of source buffers
434− if ((object)buffers != null)
435− {
436− foreach (SourceIdentifiableBuffer buffer in buffers)
437− {
438− if ((object)buffer != null)
439− buffer.Dispose();
440− }
441− }
442−
443346 // If user has attached to SourceDataParsed event, expose list of parsed data per source
444347 if ((object)SourceDataParsed != null)
445348 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t