c# - Do structs add any overhead to instance size? -


specifically, if make struct has single field, acts wrapper around value, safe pass struct p/invoke method expecting underlying type?

i'm working native library api involves lot of pointer-to-struct types, , i'd use bit more typesafe intptr keep them straight, wrapping intptr in generic struct. work? (and has been done?)

don't pass struct, then.

instead of figuring out how directly p/invoke, keep p/invoke methods private, , expose public methods take wrapper type directly - , handle whatever need pass forward. code going use these public methods without having worry unsafe structures :)

mixing different types , expecting them magically work recipe disaster. make explicit, , don't rely on hiding , implicit forced casts.

the best thing allows use pointer wrapper safe - can keep reference, , if it's ever lost, can use finalizer dispose of unmanaged resource needed. have @ how safehandle , it's descendants work great sample.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -