Hi Kashyap,
> Could you please share the example where you shared how native code
> interface could be used to malloc a section of the heap? I believe you
> shared this in the last PiCon.
I don't remember exactly, but it could have been something like (using pil21):
# Allocate 99 bytes
: (setq P (%@ "malloc" 'P 99))
-> 512227229696
# Store a long integer -1 (or FFFFFFFFFFFFFFFF)
: (struct P NIL (-1 . 8))
-> NIL
# Read a list of 8 bytes
: (struct P '(B . 8))
-> (255 255 255 255 255 255 255 255)
# Store 3 bytes
: (byte P 65) (byte (inc P) 66) (byte (+ P 2) 0)
-> 0
# Read 8 bytes again
: (struct P '(B . 8))
-> (65 66 0 255 255 255 255 255)
# Read the same as a string
: (struct P 'S)
-> "AB"
# Free the memory
: (%@ "free" NIL P)
-> NIL
Instead of heap malloc() / free() you can (again, pil21) also use a local buffer
on the stack:
: (buf P 99
(byte P 65)
(byte (inc P) 0)
(struct P 'S) )
-> "A"
☺/ A!ex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe