Pervasive
Sign in | Join | Help
in

Marshalling: Pinning vs Copying

Last post 07-03-2008 3:46 PM by Mike Reynolds. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-02-2008 12:44 AM

    Marshalling: Pinning vs Copying

    In the examples for Btrieve Classes for .NET they use the marshal functions StructureToPtr and PtrToFunction, which I think copy back and forth from managed to unmanaged memory. With the GCHandle functions you can "pin" the structure in the unmanaged heap, which sounds better since the return buffer is reused often.

    I get the impression y'all program mostly in C++ and Java, so I may be barking up the wrong tree, but I've hit a wall of fog trying to google this. If you could give me any insight into the best approach among the options I would be very obliged. I think I am getting memory corruption from improper marshalling.

     
    Mike
     

  • 07-03-2008 3:46 PM In reply to

    Re: Marshalling: Pinning vs Copying

    I've come to the conclusion that the best solution is to pin the Byte array with a GCHandle.Alloc call, and then to marshal the output to a non-blittable table structure when necessary, and marshaling the table structure back in for insert and update calls. That way I can access the data both as a Byte array and as a table structure. If I only need to access the Byte array for both input and output then I don't have to do any marshaling, and I never have to marshal more than once per Btrieve call.

     

Page 1 of 1 (2 items)
© 2008 Pervasive Software Inc. All Rights Reserved.