' Dynamic memory: ALLOCATE, REALLOCATE, FREE
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL p AS LONG
    LOCAL s AS STRING

    p = ALLOCATE(64)
    PRINT "ALLOCATE(64) at:"; p

    IF p THEN
        POKE$ p, "Dynamic memory works!"
        s = PEEK$(p, 20)
        PRINT "Stored:"; s

        p = REALLOCATE(p, 128)
        PRINT "REALLOCATE(128) at:"; p
    END IF

    PRINT "Allocate/free operations complete."

    FUNCTION = 0
END FUNCTION
