Alright, I know how you normally would declare a pointer:
void SomeFunction(array<float> ^managedArray)
{
pin_ptr<float> managedArrayPtr = &managedArray[0];
}
This works fine except when managedArray contains no elements. In that case, it throws an IndexOutOfRangeException.
In C# you can do this:
void SomeFunction(float[] managedArray)
{
fixed (float* managedArrayPtr = managedArray)
{
}
}
Which does no memory access and works even if managedArray is empty. Do I really have to check for the number of elements everywhere I use pointers to managed arrays or does C++/CLI have a way to do it like C#? It should be using the 'lea' instruction in ASM which does no memory access.
Any help is greatly appreciated!