public long test_callback_given_dynamic() { long rounds = defaultRounds; for (long i = 0; i < rounds; i++) { TestStaticDelegate t = k => k + 10; GCHandle handle = GCHandle.Alloc(t); dummyResult += pinvokeTest_invokeGivenDynamicCallback(testDynamicDelegatePtr, GCHandle.ToIntPtr(handle), 1); handle.Free(); } return rounds; }
public long test_callback_stored_dynamic() { long rounds = defaultRounds; TestStaticDelegate t = k => k; GCHandle handle = GCHandle.Alloc(t); pinvokeTest_setDynamicCallback(testDynamicDelegatePtr); for (long i = 0; i < rounds; i++) { dummyResult += pinvokeTest_invokeStoredDynamicCallback(GCHandle.ToIntPtr(handle), 1); } handle.Free(); return rounds; }
public PInvokeTests() { testStaticDelegate = testStaticCallback; testStaticDelegatePtr = Marshal.GetFunctionPointerForDelegate(testStaticDelegate); testDynamicDelegate = testDynamicCallback; testDynamicDelegatePtr = Marshal.GetFunctionPointerForDelegate(testDynamicDelegate); }