PooledGrowableBufferHelper 1.0.14
.NET Core 2.1
This package targets .NET Core 2.1. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6
This package targets .NET Framework 4.6. The package is compatible with this framework or higher.
dotnet add package PooledGrowableBufferHelper --version 1.0.14
NuGet\Install-Package PooledGrowableBufferHelper -Version 1.0.14
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PooledGrowableBufferHelper" Version="1.0.14" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PooledGrowableBufferHelper --version 1.0.14
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PooledGrowableBufferHelper, 1.0.14"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PooledGrowableBufferHelper as a Cake Addin #addin nuget:?package=PooledGrowableBufferHelper&version=1.0.14 // Install PooledGrowableBufferHelper as a Cake Tool #tool nuget:?package=PooledGrowableBufferHelper&version=1.0.14
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
A simple library providing reusable MemoryStream implementation and IBufferWriter<byte> implementation. It is suitable for storing temporary byte stream.
The underlying buffer is rented from ArrayPool<byte>.Shared.
Features
- Implements a MemoryStream-like reusable stream, whose underlying buffer is dynamically rented from ArrayPool<byte>.Shared when more space is needed and returned when Close/Dispose is called.
- Uses a linked list to track buffers rented for a stream instance.
- Implements IBufferWriter<byte> interface, which can be used to append data to the end of the stream.
- Provides a ReadOnlySequence<byte> view over the content in the stream.
Examples
Use as a temporary buffer (like a MemoryStream)
using (PooledMemoryStream ms = PooledMemoryStreamManager.Shared.GetStream())
{
ms.Write(buffer1, 0, 12);
ms.Write(buffer2, 0, 12);
// Seeking to the begining of the stream is very cheep.
// However, seeking to other random position may not be.
ms.Seek(0, SeekOrigin.Begin);
await ms.CopyToAsync(reaponse.Body);
}
// Please make sure Close/Dispose is called so that rented buffer can be returned to the pool
Use as a IBufferWriter<byte>
using (PooledMemoryStream ms = PooledMemoryStreamManager.Shared.GetStream())
{
IBufferWriter<byte> writer = ms;
Span<byte> span = writer.GetSpan(16);
span[0] = 'A';
...
span[11] = 'a';
writer.Advance(12);
// When swithing usage from IBufferWriter-base API to stream-based API, make sure Advance is called and no buffer is acquired though GetMemory/GetSpan
// When swithing usage from stream-based API to IBufferWriter-base API, make sture the position is at the end of the stream.
byte[] arr = ms.ToArray[];
}
Use ReadOnlySequence<byte> as a view over the buffer
using (PooledMemoryStream ms = PooledMemoryStreamManager.Shared.GetStream())
{
ms.Write(buffer1, 0, 12);
ReadOnlySequence<byte> sequence = ms.ToReadOnlySequence();
// Don't mutate the content when working with ReadOnlySequence<byte>
}
Use as MemoryStream
If you have a function that accept MemoryStream instad of Stream, you can call AsMemoryStream to acquire a MemoryStream wrapper of the original stream.
using (PooledMemoryStream ms = PooledMemoryStreamManager.Shared.GetStream())
{
MemoryStream s = ms.AsMemoryStream(leaveOpen: true);
SomeFunction(s);
}
void SomeFunction(MemoryStream ms)
{
...
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETFramework 4.6
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.4)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.4)
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on PooledGrowableBufferHelper:
Package | Downloads |
---|---|
OpenSlideNET.ImageExtensions
.NET bindings for OpenSlide with Deep Zoom support. |
GitHub repositories
This package is not used by any popular GitHub repositories.