FB II Compiler
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?
err% = SYSERROR
siz& = FN GETHANDLESIZE(resHand&)
LONG IF resHand& <>0 and err%=_false 'NOT err%
adr&=PEEK LONG (resHand&)
BLOCKMOVE adr&, recAdr&, _bSz
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.