@StainlessTobii wrote:
Hi Guys,
I have started porting my terrain system to MonoGame and have come across an interesting issue.
To prevent garbage collections, I have written a memory manager for my renderer.
At boot up it allocates some arrays and uses a grow only allocator
The problem is that C# is manically type safe.
So I cannot read an array of shorts into a buffer in one hit.
As far as I can see the only way to read the data into an array is to loop over each value in the array reading a single short at a time. MUCH , MUCH , too slow.
I have thought about using a binaryformatter, but that doesn't use my memory allocator and everything falls apart.
I have thought about having a temporary byte array, but it is entirely possible that I may have several terrain patches streaming in at the same time, so that becomes impracticable.
So I am going to try using a struct instead of an array and using [StructLayout(LayoutKind.Explicit)] to effectively create a union of two arrays (byte and short). So the code becomes....
ShortHeights.Shorts = RenderMemoryManager.GetShortMemory(RenderMemoryManager.MemoryUsage.HeightMap, AllocationSize, out ShortHandle); stream.Read(ShortHeights.Bytes, 0, AllocationSize);
Anybody got a better solution
Posts: 3
Participants: 2