public static InstallationProxyError instproxy_lookup(InstallationProxyClientHandle client, System.Collections.ObjectModel.ReadOnlyCollection <string> appids, PlistHandle clientOptions, out PlistHandle result) { System.Runtime.InteropServices.ICustomMarshaler appidsMarshaler = NativeStringArrayMarshaler.GetInstance(null); System.IntPtr appidsNative = appidsMarshaler.MarshalManagedToNative(appids); InstallationProxyError returnValue = InstallationProxyNativeMethods.instproxy_lookup(client, appidsNative, clientOptions, out result); return(returnValue); }
public static DebugServerError debugserver_command_new(string name, int argc, System.Collections.ObjectModel.ReadOnlyCollection <string> argv, out DebugServerCommandHandle command) { System.Runtime.InteropServices.ICustomMarshaler argvMarshaler = NativeStringArrayMarshaler.GetInstance(null); System.IntPtr argvNative = argvMarshaler.MarshalManagedToNative(argv); DebugServerError returnValue = DebugServerNativeMethods.debugserver_command_new(name, argc, argvNative, out command); return(returnValue); }
public void TestRoundTrip() { NativeLibraries.Load(); // Create a string array worth +/- 10 MB of memory var values = new List <string>(); values.Add(new string('0', 1024 * 1024)); values.Add(new string('1', 1024 * 1024)); values.Add(new string('2', 1024 * 1024)); values.Add(new string('3', 1024 * 1024)); values.Add(new string('4', 1024 * 1024)); values.Add(new string('5', 1024 * 1024)); values.Add(new string('6', 1024 * 1024)); values.Add(new string('7', 1024 * 1024)); values.Add(new string('8', 1024 * 1024)); values.Add(new string('9', 1024 * 1024)); // And, as the icing on the cake, an UTF-8 string. values.Add("Bart’s iPhone"); var readonlyValues = new ReadOnlyCollection <string>(values); GC.Collect(); var p = Process.GetCurrentProcess(); var initialMemory = p.PrivateMemorySize64; for (int i = 0; i < 75; i++) { NativeStringArrayMarshaler marshaler = new NativeStringArrayMarshaler(); var pointer = marshaler.MarshalManagedToNative(readonlyValues); marshaler = null; GC.Collect(); marshaler = new NativeStringArrayMarshaler(); var roundTrip = (ReadOnlyCollection <string>)marshaler.MarshalNativeToManaged(pointer); CollectionAssert.AreEqual(readonlyValues, roundTrip); marshaler.CleanUpNativeData(pointer); } GC.Collect(); p.Refresh(); var currentMemory = p.PrivateMemorySize64; var delta = currentMemory - initialMemory; // If more than 10 MB was leaked, set off the alarm bells // You can verify this works by commenting out NativeStringMarshaler.CleanUpNativeData if (delta > 10 * 1024 * 1024 * 8 /* 10 MB */) { Assert.Fail("Memory was leaked"); } }
public static DebugServerError debugserver_client_set_argv(DebugServerClientHandle client, int argc, System.Collections.ObjectModel.ReadOnlyCollection <string> argv, out string response) { System.Runtime.InteropServices.ICustomMarshaler responseMarshaler = NativeStringMarshaler.GetInstance(null); System.IntPtr responseNative = System.IntPtr.Zero; System.Runtime.InteropServices.ICustomMarshaler argvMarshaler = NativeStringArrayMarshaler.GetInstance(null); System.IntPtr argvNative = argvMarshaler.MarshalManagedToNative(argv); DebugServerError returnValue = DebugServerNativeMethods.debugserver_client_set_argv(client, argc, argvNative, out responseNative); response = ((string)responseMarshaler.MarshalNativeToManaged(responseNative)); responseMarshaler.CleanUpNativeData(responseNative); return(returnValue); }