How to "pin" C++/CLI pointers
- by Kumar
I am wrapping up a class which reading a custom binary data file and makes the data available to a .net/c# class
However a couple of lines down the code, i start getting the memory access violation error which i believe is due to the GC moving memory around, the class is managed
Here's the code
if ( ! reader.OpenFile(...) )
return ;
foreach(string fieldName in fields)
{
int colIndex = reader.GetColIndex( fieldName );
int colType = reader.GetColType( colIndex ); // error is raised here on 2nd iteration
}
for ( int r = 0 ; r < reader.NumFields(); r++ )
{
foreach(string fieldName in fields)
{
int colIndex = reader.GetColIndex( fieldName );
int colType = reader.GetColType( colIndex ); // error is raised here on 2nd iteration
switch ( colType )
{
case 0 : // INT
processField( r, fieldName, reader.GetInt(r,colIndex) );
break ;
....
}
}
}
....
i've looked at interior_ptr, pin_ptr but they give an error c3160 cannot be in a managed class
Any workaround ? BTW, this is my 1st C++ program in a very long time !