gchandle
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
gchandle [2018/09/07 04:23] – wolfgangriedmann | gchandle [2018/09/07 04:23] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 8: | Line 8: | ||
Basically, you can get a handle from an object and lock it in memory so the garbage collector will not move it around: <code visualfoxpro> | Basically, you can get a handle from an object and lock it in memory so the garbage collector will not move it around: <code visualfoxpro> | ||
- | oHandle := GCHandle.Alloc( oMyObject )< | + | oHandle := GCHandle.Alloc( oMyObject )</code> |
and then get a pointer to it: <code visualfoxpro> | and then get a pointer to it: <code visualfoxpro> | ||
- | ptrObject := GCHandle.ToIntPtr( oHandle )< | + | ptrObject := GCHandle.ToIntPtr( oHandle )</code> |
To return then the object from the IntPtr (that is 32 bit wide in x86 mode, and 64 bit in x64 mode), you can use this code: <code visualfoxpro> | To return then the object from the IntPtr (that is 32 bit wide in x86 mode, and 64 bit in x64 mode), you can use this code: <code visualfoxpro> | ||
local oObject as MyObject | local oObject as MyObject | ||
oHandle := GCHandle.FromIntPtr( ptrObject ) | oHandle := GCHandle.FromIntPtr( ptrObject ) | ||
- | oObject := (MyObject) GCHandle.Target< | + | oObject := (MyObject) GCHandle.Target< |
And since you have locked this object in memory, it is very important to release it also with | And since you have locked this object in memory, it is very important to release it also with | ||
<code visualfoxpro> | <code visualfoxpro> |
gchandle.txt · Last modified: 2018/09/07 04:23 by wolfgangriedmann