[Prev][Next][Index][Thread]
A92: RE: Handle's Messiah
>
>Sorry for the pun. I have been totally confused with handles. I can
>allocate and free them without any trouble. But I can't seem to use them.
>I get "Address Error" and "Line 1111 Emulator" errors. Am I completely
>using them incorrectly? (see the following code)
>
>move.l #2,-(a7)
>jsr tios::HeapAlloc
>lea 4(a7),a7
>cmp.l #0,d0
>beq \UnableToAlloc
OK so far...
Here's where you go wrong:
>move.w d0,a0
>clr.w 0(a0)
The value in d0.w is the handle - NOT the adress. To get the adress that the handle points to, use this:
tios::DEREF d0,a0
Note that this destroys d0 (I think, read tios.h). Also, tios::DEREF is a macro. You can cut'n'paste the code into your own program if you don't want to destroy d0. You can also get the adress in another adress register.
>move.w d0,-(a7)
>jsr tios::HeapFree
>lea 2(a7),a7
>\UnableToAlloc:
>
>Does this program correctly allocate 2 bytes, clear them, and then free the
>memory?
Two out of three ain't bad ;-)