I have a quite large float array (usually >40 million entries) which takes up between 150MB und 250MB megabytes in memory and I need to pass it to two different APIs. Both are thrid party tools which I can't change. One of which only accepts byte[] and the other one only ref float[].
It is not a problem for me to convert it to a byte[] using Buffer.BlockCopy or similar approaches. But due to memory fragmentation allocating an array of this size fails regularly, and I would like to avoid copying it if possible.
Is there any way, to accomplish this? Maybe using unsafe code or C++ cli or C++ or a combination of all of them? Or maybe using MemoryMappedFile? I have already tried all of these but so far without any success.