Buffering 0.2.0
See the version list below for details.
dotnet add package Buffering --version 0.2.0
NuGet\Install-Package Buffering -Version 0.2.0
<PackageReference Include="Buffering" Version="0.2.0" />
paket add Buffering --version 0.2.0
#r "nuget: Buffering, 0.2.0"
// Install Buffering as a Cake Addin #addin nuget:?package=Buffering&version=0.2.0 // Install Buffering as a Cake Tool #tool nuget:?package=Buffering&version=0.2.0
Buffering
This library provides very easy and streamlined functionality for implementing different kinds of buffers in any system. Currently, there is only a double buffer to maximize throughput between a source and destination with the most up-to-date information from the source.
Threadsafe
All buffers are implemented in a threadsafe manner using the most efficient object-oriented implementation involving a lock and handle that only needs to be disposed after you're done.
Double Buffer Example
Here is an example of how simple it is to set up a double buffer:
This creates a double buffer using the given configuration (yeah, multiple ways you can define how a buffer works) and a cancellation token source to define a runtime length of the program:
var db = new DoubleBuffer<Vector3>(
rsc: new BufferingResource<Vector3>(
init: () => Vector3.Zero,
updater: (ref Vector3 rsc, bool _) => rsc = new Vector3(rsc.X + 1F)),
configuration: new DoubleBufferConfiguration(
lockImpl: new MonitorLock(),
swapEffect: DoubleBufferSwapEffect.Flip));
var cts = new CancellationTokenSource(10_000);
This next part creates the long-running back buffer update thread:
var bufferUpdateTask = new TaskFactory(TaskCreationOptions.LongRunning, 0).StartNew(() =>
{
var token = cts.Token;
var controller = db.BackController;
while (!token.IsCancellationRequested)
{
controller.UpdateBackBuffer();
controller.SwapBuffers();
}
});
Finally, the portion of the program that reads the buffer until the task is over and it updates no more:
var reader = db.FrontReader;
while (!bufferUpdateTask.IsCompleted)
{
reader.ReadFrontBuffer(out var rsc, out var rscInfo).Dispose();
Console.WriteLine($"{rscInfo.Id:N0}: {rsc} : {rscInfo}");
}
That's all there is to creating a double buffer and using it at very performant speeds with minimal lock times.
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 is compatible. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added a single buffer and full documentation