[Mono-devel-list] IntPtr versus Marshaling

christopher.p.taylor at us.army.mil christopher.p.taylor at us.army.mil
Thu Mar 18 15:29:58 EST 2004


Hey everyone I've a `burning` question about marshaling and IntPtr's, 

 So I'm writing a binding for a C lib on gnu/linux and I've been using the Cairo bindings as my guide. I noticed in Cairo#, Duncan used IntPtr for all references to the C structure. I noticed you can also Marshal classes and structs by defining them and then using a StructLayout attribute to get the structure into a more "natural form" instead of making calls to an IntPtr.

Which is the "better" of the two?  Granted "better" is kinda relative, but you can always write C functions to get/set data in the C structure and do another DllImport on that "glue lib". Is the IntPtr approach faster than marshaling (I'm assuming so)? Or is it done mainly in the event that some platform is doing strange things at the ABI level? Are there any advantages or disadvantages I'm not picking up on?

Much thanks,
Chris




More information about the Mono-devel-list mailing list