An example will make this clear:
unsafe void ProcessUnmanagedBuffer( float * buffer, int length )
{
int i;
for( i = 0; i < length; i++ )
{
buffer[ i ] = ...;
}
}
void ProcessManagedBuffer( float[] buffer, int length )
{
int i;
for( i = 0; i < length; i++ )
{
buffer[ i ] = ...;
}
}
// common interface to avoid duplicate code?
void ProcessBuffer( IndexableThing buffer, int length )
Of course, there can't be a common interface since float * isn't a class.
The obvious solution is to wrap and override the indexer, but for performance critical code this is far from ideal.
The less obvious one would be to pin the float[] and get a pointer to it. Better, but pinning incurs some overhead too.
I suspect there is no good solution - any ideas?