Click here to Skip to main content
15,902,636 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Creating objects on stack Pin
Paul Selormey3-Mar-03 23:47
Paul Selormey3-Mar-03 23:47 
GeneralRe: Creating objects on stack Pin
VizOne10-Mar-03 1:45
VizOne10-Mar-03 1:45 
GeneralRe: Creating objects on stack Pin
Paul Selormey9-Mar-03 17:07
Paul Selormey9-Mar-03 17:07 
GeneralMixins and __gc Pin
-=jarl=-27-Feb-03 3:59
-=jarl=-27-Feb-03 3:59 
GeneralRe: Mixins and __gc Pin
Paul Selormey27-Feb-03 22:11
Paul Selormey27-Feb-03 22:11 
GeneralRe: Mixins and __gc Pin
-=jarl=-6-Mar-03 1:14
-=jarl=-6-Mar-03 1:14 
GeneralHandles and pointers... Pin
-=jarl=-26-Feb-03 7:28
-=jarl=-26-Feb-03 7:28 
GeneralRe: Handles and pointers... Pin
Jeff J26-Feb-03 16:46
Jeff J26-Feb-03 16:46 
Not really. GCHandle is more versatile than a pointer pinned via __pin. A pinned pointer only remains pinned while it is in scope, and if not set to zero. For example, when a function that uses pinned pointers returns, any pinned objects are no longer pinned. I suppose one could just say the __pin is used on stack-allocated pointers.

GCHandle, on the other hand, allocates on the heap (which is why Free() must be called to release an Alloc()-allocated GCHandle). There are a few options for GCHandles, but a regular one stays allocated between function calls, like any object allocated via malloc() or unmanaged new.

Which is safer? Well, that depends on the lifetime requirements you have for the object in question. If the handle needs to remain pinned/valid when it goes out of scope, GCHandle would be the safe bet.

Cheers
GeneralRe: Handles and pointers... Pin
-=jarl=-26-Feb-03 23:19
-=jarl=-26-Feb-03 23:19 
GeneralManaged and Unmanaged structures Pin
-=jarl=-26-Feb-03 6:55
-=jarl=-26-Feb-03 6:55 
GeneralRe: Managed and Unmanaged structures Pin
-=jarl=-26-Feb-03 6:58
-=jarl=-26-Feb-03 6:58 
GeneralRe: Managed and Unmanaged structures Pin
Paul Selormey26-Feb-03 13:51
Paul Selormey26-Feb-03 13:51 
GeneralRe: Managed and Unmanaged structures Pin
-=jarl=-26-Feb-03 23:16
-=jarl=-26-Feb-03 23:16 
GeneralRe: Managed and Unmanaged structures Pin
Paul Selormey27-Feb-03 0:20
Paul Selormey27-Feb-03 0:20 
GeneralRe: Managed and Unmanaged structures Pin
-=jarl=-27-Feb-03 0:22
-=jarl=-27-Feb-03 0:22 
GeneralManaged/Unmanaged: pinning ptr madness Pin
VizOne25-Feb-03 22:04
VizOne25-Feb-03 22:04 
GeneralRe: Managed/Unmanaged: pinning ptr madness Pin
Jeff J26-Feb-03 16:24
Jeff J26-Feb-03 16:24 
GeneralRe: Managed/Unmanaged: pinning ptr madness Pin
VizOne27-Feb-03 1:56
VizOne27-Feb-03 1:56 
GeneralRe: Managed/Unmanaged: pinning ptr madness Pin
VizOne28-Feb-03 0:31
VizOne28-Feb-03 0:31 
GeneralRe: Managed/Unmanaged: pinning ptr madness Pin
Jeff J28-Feb-03 22:25
Jeff J28-Feb-03 22:25 
GeneralImplementing IDisposable Pin
VizOne24-Feb-03 9:49
VizOne24-Feb-03 9:49 
GeneralRe: Implementing IDisposable Pin
Paul Selormey25-Feb-03 0:23
Paul Selormey25-Feb-03 0:23 
GeneralRe: Implementing IDisposable Pin
VizOne25-Feb-03 0:30
VizOne25-Feb-03 0:30 
GeneralRe: Implementing IDisposable Pin
Paul Selormey25-Feb-03 0:49
Paul Selormey25-Feb-03 0:49 
GeneralRe: Implementing IDisposable Pin
VizOne25-Feb-03 0:58
VizOne25-Feb-03 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.