User Tools

Site Tools


gchandle

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
gchandle [2018/09/07 04:23] wolfgangriedmanngchandle [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>local oHandle as GCHandle 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>local oHandle as GCHandle
-oHandle := GCHandle.Alloc( oMyObject )<code>+oHandle := GCHandle.Alloc( oMyObject )</code>
 and then get a pointer to it: <code visualfoxpro>local ptrObject as IntPtr and then get a pointer to it: <code visualfoxpro>local ptrObject as IntPtr
-ptrObject := GCHandle.ToIntPtr( oHandle )<code>+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>local oHandle as GCHandle 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 oHandle as GCHandle
 local oObject as MyObject local oObject as MyObject
 oHandle := GCHandle.FromIntPtr( ptrObject ) oHandle := GCHandle.FromIntPtr( ptrObject )
-oObject := (MyObject) GCHandle.Target<code>+oObject := (MyObject) GCHandle.Target</code>
 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>oHandle:Free()</code> <code visualfoxpro>oHandle:Free()</code>
gchandle.txt · Last modified: 2018/09/07 04:23 by wolfgangriedmann