B
bbembi_de
Hello,
I use a C++ Dll in .Net 1.1 with Dllimport.
I call one C++ method in a loop and the memory of my .Net application
rises proportional.
What am I doing wrong calling this method?
Simplified it's like this:
[StructLayout(LayoutKind.Sequential)]
public struct MyStruct {
[MarshalAs(UnmanagedType.LPStr)] public string name;
public int media;
}
Test 1:
[DllImport("ToolkitApiDll.dll", ExactSpelling=true)]
public static extern int GetData(IntPtr mystruct);
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MyStruct)));
GetData(ptr);
MyStruct m = (MyStruct) Marshal.PtrToStructure(ptr, typeof(MyStruct));
GetData(ptr);
Marshal.FreeHGlobal(ptr);
Test 2:
[DllImport("ToolkitApiDll.dll", ExactSpelling=true)]
public static extern int GetData(ref MyStruct mystruct);
MyStruct m = new MyStruct();
GetData(ref m);
Both ways I get the data but the memory rises.
Any ideas?
Thanks.
bye bembi
I use a C++ Dll in .Net 1.1 with Dllimport.
I call one C++ method in a loop and the memory of my .Net application
rises proportional.
What am I doing wrong calling this method?
Simplified it's like this:
[StructLayout(LayoutKind.Sequential)]
public struct MyStruct {
[MarshalAs(UnmanagedType.LPStr)] public string name;
public int media;
}
Test 1:
[DllImport("ToolkitApiDll.dll", ExactSpelling=true)]
public static extern int GetData(IntPtr mystruct);
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MyStruct)));
GetData(ptr);
MyStruct m = (MyStruct) Marshal.PtrToStructure(ptr, typeof(MyStruct));
GetData(ptr);
Marshal.FreeHGlobal(ptr);
Test 2:
[DllImport("ToolkitApiDll.dll", ExactSpelling=true)]
public static extern int GetData(ref MyStruct mystruct);
MyStruct m = new MyStruct();
GetData(ref m);
Both ways I get the data but the memory rises.
Any ideas?
Thanks.
bye bembi