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

Made with FB

MEMORY

Use HandAndHand Toolbox call


OSErr% = fn HandAndHand(srcHdl&, destHdl&) appends the contents of srcHdl& onto the end of destHdl&, modifying destHdl&'s size and leaving srcHdl& untouched. It returns an OSErr% of zero if successful, -108 if memory is full, -109 if a handle is invalid, and -111 if an attempt was made to operate on a free block. HandAndHand moves memory so be sure the handles are locked. I use this (FBII) function whenever I call it (courtesy of Osamu Shigematsu):
LOCAL FN handNhand(aHndl&,bHndl&)'copies from aHndl& to bHndl&
DIM osErr%
DIM aState%,bState%,aSize%
DIM freemem&

LONG IF aHndl&<>_nil AND bHndl&<>_nil
   aState% = FN HGETSTATE(aHndl&)
   bState% = FN HGETSTATE(bHndl&)
   aSize% = FN GETHANDLESIZE(aHndl&)
   freemem& = MEM(_freeBytes)'amount of free memory in bytes
   LONG IF freemem& - aSize% > _kMemDangerLevel
     osErr% = FN HLOCK(aHndl&)
     osErr% = FN HLOCK(bHndl&)
     osErr% = FN HANDANDHAND(aHndl&,bHndl&)
     LONG IF osErr% = _noErr
       osErr% = FN HSETSTATE(bHndl&,bState%)
     XELSE
       bHndl& = FN disposeh(bHndl&)
     END IF
     osErr% = FN HSETSTATE(aHndl&,aState%)
   XELSE
     'we're nearly out of memory so don't move the data
     gMemLow% = _zTrue
   END IF
END IF
END FN = bHndl&
This fn is called like this: destHdl& = fn handNhand(srcHdl&, destHdl&). If the HANDANDHAND operation fails destHdl& is returned as a _nil handle. Plus I built in a memory check: if memory is low, it leaves everything untouched. If the operation is successful both handles are left in the same lock/unlocked state. Works for me. It could easily be modified to return OSErr% and leave destHdl& untouched if that suits you.
I don't use HandToHand for anything. The notion of putting one handle in and getting another out goes against the grain...
Steve

Note for FB^3.
Go to the current def for HANDANDHAND. Add in a second long integer parameter. Everything will work.
Your code would normally be a perfect translation, but a few of the older memory manager calls use specific registers in 68K mode and must be hand tooled. The working version is...
toolbox fn HandAndHand(long,long) = word `0x205F,0xA9E4,0xC188
The word "HandAndHand" is actually the only case in FB where something is case sensetive. This is a PPC requirement and not something that is our choice. If you want to see what combination of upper and lower case characters were used in the toolbox calls, temporarily turn them into a remark or a quote so that the editor does not automatically ucase them.
STAZ