14.6.1.0707
ALLOCATE
 
MEMORY
 
( u -- a-addr ior )

Allocate u address units of contiguous data space. The data-space pointer is unaffected by this operation. The initial content of the allocated space is undefined.

If the allocation succeeds, a-addr is the aligned starting address of the allocated space and ior is zero.

If the operation fails, a-addr does not represent a valid address and ior is the implementation-defined I/O result code.

Testing:
VARIABLE datsp
HERE datsp !

T{ 50 CELLS ALLOCATE SWAP addr ! -> 0 }T
T{ addr @ ALIGNED -> addr @ }T    \ Test address is aligned
T{ HERE -> datsp @ }T              \ Check data space pointer is unaffected
addr @ 50 write-cell-mem
addr @ 50 check-cell-mem         \ Check we can access the heap
T{ addr @ FREE -> 0 }T

T{ 99 ALLOCATE SWAP addr ! -> 0 }T
T{ addr @ ALIGNED -> addr @ }T    \ Test address is aligned
T{ addr @ FREE -> 0 }T
T{ HERE -> datsp @ }T              \ Data space pointer unaffected by FREE
T{ -1 ALLOCATE SWAP DROP 0= -> <FALSE> }T    \ Memory allocate failed