
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
RESOURCES
Know if one must lock a resource handle
I was looking over some code in my program and all of a sudden I got nervous. The following bit of code works, but should I be locking resHand& before copying data from it?
resHand&=FN GETRESOURCE(_"GeoJ",id)
err% = SYSERROR
siz& = FN GETHANDLESIZE(resHand&)
LONG IF resHand& <>0 and err%=_false 'NOT err%
CALL SETRESLOAD(_True)
CALL LOADRESOURCE(resHand&)
adr&=PEEK LONG (resHand&)
recAdr&=@gGrad
BLOCKMOVE adr&, recAdr&, _bSz
END IF
CALL RELEASERESOURCE(resHand&)
------
No. BlockMove does not move memory, and neither does Peek. Locking the handle won't hurt anything, but it simply isn't necessary in this fragment.
In general terms, it *is* a good idea to lock a handle before doing anything "serious" with it. BlockMove, however, is a special case.
|