14.6.1.0707 ALLOCATE MEMORY
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.
See:
Testing:
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
ContributeContributions
MitraArdron [174] write-cell-mem undefinedRequest for clarification2021-01-13 03:56:09
In the test cases for ALLOCATE it uses words which as far as I can see are neither standard nor defined. Specifically write-cell-mem and check-cell-mem which aren't defined.
Also ... It looks to me like ALLOCATE has to store the size somewhere so that FREE can work, since FREE doesn't get passed the size. Should that be clarified?