PointerMemory<T>
PointerMemory(ptr, count) adapts 'ptr' and 'count' to memory access.
unsafe
{
long[] data = new long[1024];
fixed (long* ptr = data)
{
PointerMemory<long> memory = new PointerMemory<long>(ptr, data.Length);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
}
}
PointerMemory(ref, count) adapts 'ref' pointer and 'count' to memory access.
long[] data = new long[1024];
PointerMemory<long> memory = new PointerMemory<long>(ref data[0], 1024);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
Span<T>
PointerMemory(span) adapts 'span' to memory access.
Span<long> span = new long[1024];
PointerMemory<long> memory = new PointerMemory<long>(span);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
ReadOnlyPointerMemory<T>
ReadOnlyPointerMemory(ptr, count) adapts 'ptr' and 'count' to memory access.
unsafe
{
long[] data = new long[1024];
fixed (long* ptr = data)
{
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(ptr, data.Length);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
}
}
ReadOnlyPointerMemory(ref, count) adapts 'ref' pointer and 'count' to memory access.
long[] data = new long[1024];
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(ref data[0], 1024);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
ReadOnlyPointerMemory(span) adapts 'span' to memory access.
Span<long> span = new long[1024];
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(span);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
Full Example
Full example
using Avalanche.Memory;
public class pointermemory
{
public static void Run()
{
{
// <01>
unsafe
{
long[] data = new long[1024];
fixed (long* ptr = data)
{
PointerMemory<long> memory = new PointerMemory<long>(ptr, data.Length);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
}
}
// </01>
}
{
// <02>
long[] data = new long[1024];
PointerMemory<long> memory = new PointerMemory<long>(ref data[0], 1024);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
// </02>
}
{
// <03>
Span<long> span = new long[1024];
PointerMemory<long> memory = new PointerMemory<long>(span);
for (long ix = 0L; ix < memory.Count; ix++) memory[ix] = ix;
// </03>
}
{
// <21>
unsafe
{
long[] data = new long[1024];
fixed (long* ptr = data)
{
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(ptr, data.Length);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
}
}
// </21>
}
{
// <22>
long[] data = new long[1024];
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(ref data[0], 1024);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
// </22>
}
{
// <23>
Span<long> span = new long[1024];
ReadOnlyPointerMemory<long> memory = new ReadOnlyPointerMemory<long>(span);
for (int i = 0; i < 3; i++) Console.WriteLine(memory[i]);
// </23>
}
}
}