Memory<T> and Span<T>
Posted: Thu Sep 30, 2021 10:20 pm
Hello,
Is there any plan to make the charts support Memory<T> and Span<T> structures? These are extremely useful for optimizing memory usage, for example, by using ArrayPool<T>. Since the ArrayPool might not give you a buffer of the exact size requested, you can wrap that in a Span or Memory structure.
I have a monitor application that updates SampleDataSeries rapidly using data from a remote source. The data acquisition tasks use the ArrayPool<T> for memory efficiency and to minimize new memory allocations and garbage collection. Unfortunately, right when I add the samples to the series, it has to be moved to a different buffer or use the .ToArray() method, which potentially causes more allocations. It would be great if LightningCharts accepted these structure directly.
For example (Pseudo code):
Thanks!
Jon
Is there any plan to make the charts support Memory<T> and Span<T> structures? These are extremely useful for optimizing memory usage, for example, by using ArrayPool<T>. Since the ArrayPool might not give you a buffer of the exact size requested, you can wrap that in a Span or Memory structure.
I have a monitor application that updates SampleDataSeries rapidly using data from a remote source. The data acquisition tasks use the ArrayPool<T> for memory efficiency and to minimize new memory allocations and garbage collection. Unfortunately, right when I add the samples to the series, it has to be moved to a different buffer or use the .ToArray() method, which potentially causes more allocations. It would be great if LightningCharts accepted these structure directly.
For example (Pseudo code):
Code: Select all
var pool = new ArrayPool<float>.Shared;
var buf = pool.Rent(5000); //buf might not be exactly length 5000 (it's probably 8192)
var mem = new Memory<float>(buf, 5000); //Wrap it with a Memory<T> of length 5000.
for (var i=0; i < mem.Length; i++){
//Populate buffer with some data
mem[i] = i;
}
//Plot the 5000 samples
_chart.ViewXY.SampleDataSeries[0].AddSamples(mem.toArray(), true);//This is inefficient and causes allocations
_chart.ViewXY.SampleDataSeries[0].AddSamples(mem, true); //This would be better!
Thanks!
Jon