This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from justcoding121/beta
Stable
- Loading branch information
Showing
38 changed files
with
3,476 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Concurrent; | ||
|
||
namespace StreamExtended | ||
{ | ||
|
||
/// <summary> | ||
/// A concrete IBufferPool implementation using a thread-safe stack. | ||
/// Works well when all consumers ask for buffers with the same size. | ||
/// If your application would use size buffers consider implementing IBufferPool using System.Buffers library from Microsoft. | ||
/// </summary> | ||
public class DefaultBufferPool : IBufferPool | ||
{ | ||
private readonly ConcurrentStack<byte[]> buffers = new ConcurrentStack<byte[]>(); | ||
|
||
/// <summary> | ||
/// Gets a buffer. | ||
/// </summary> | ||
/// <param name="bufferSize">Size of the buffer.</param> | ||
/// <returns></returns> | ||
public byte[] GetBuffer(int bufferSize) | ||
{ | ||
if (!buffers.TryPop(out var buffer) || buffer.Length != bufferSize) | ||
{ | ||
buffer = new byte[bufferSize]; | ||
} | ||
|
||
return buffer; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the buffer. | ||
/// </summary> | ||
/// <param name="buffer">The buffer.</param> | ||
public void ReturnBuffer(byte[] buffer) | ||
{ | ||
if (buffer != null) | ||
{ | ||
buffers.Push(buffer); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
buffers.Clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace StreamExtended | ||
{ | ||
/// <summary> | ||
/// Use this interface to implement custom buffer pool. | ||
/// To use the default buffer pool implementation use DefaultBufferPool class. | ||
/// </summary> | ||
public interface IBufferPool : IDisposable | ||
{ | ||
byte[] GetBuffer(int bufferSize); | ||
void ReturnBuffer(byte[] buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.