A
Ananas
Hi,
My native C++ function creates a dynamic array. I'm marshalling it to
managed code and got to delete after. How to make it:
c++ code:
void CreateArrayInside( pTestStruct &TestStruct,
unsigned int &size)
{
size = 5000;
// test structure
TestStruct = new CTestStruct[size];
}
c# declaration:
[DllImport( "MathDll.dll", CharSet = CharSet.Auto, EntryPoint =
"CreateArrayInside" )]
public static extern void CreateArrayInside( ref IntPtr
TestStructArray, out uint size );
c# usage:
IntPtr pTestStructs = new IntPtr();
uint Count;
for ( uint i = 0; i < 20000; i++ )
{
MathDLLWrapper.Interface.CreateArrayInside( ref pTestStructs, out
Count );
// Marshal.FreeCoTaskMem( pTestStructs );
Console.WriteLine("Loop: " + i);
}
I tried to use Marshal.FreeCoTaskMem( pTestStructs ) but memory get
leaks. As it is said in the msdn the FreeCoTaskMem got to be used for
to free up memory allocated for COM tasks.
Is there any way to free up memory allocated by C++ part?
Please give an advise.
Thanks,
Eugene.
Marshal.FreeHGlobal( pTestStructs );
My native C++ function creates a dynamic array. I'm marshalling it to
managed code and got to delete after. How to make it:
c++ code:
void CreateArrayInside( pTestStruct &TestStruct,
unsigned int &size)
{
size = 5000;
// test structure
TestStruct = new CTestStruct[size];
}
c# declaration:
[DllImport( "MathDll.dll", CharSet = CharSet.Auto, EntryPoint =
"CreateArrayInside" )]
public static extern void CreateArrayInside( ref IntPtr
TestStructArray, out uint size );
c# usage:
IntPtr pTestStructs = new IntPtr();
uint Count;
for ( uint i = 0; i < 20000; i++ )
{
MathDLLWrapper.Interface.CreateArrayInside( ref pTestStructs, out
Count );
// Marshal.FreeCoTaskMem( pTestStructs );
Console.WriteLine("Loop: " + i);
}
I tried to use Marshal.FreeCoTaskMem( pTestStructs ) but memory get
leaks. As it is said in the msdn the FreeCoTaskMem got to be used for
to free up memory allocated for COM tasks.
Is there any way to free up memory allocated by C++ part?
Please give an advise.
Thanks,
Eugene.
Marshal.FreeHGlobal( pTestStructs );