Byte
Byte

Reputation: 509

Contiguous memory in Forth arrays?

I know that variable test 5 cells allot is not guaranteed to allocate a contiguous block of memory, while create test 1 , 2 , 3 , 4 , 5 , will definitely create a contiguous block of memory.

variable is defined as : variable create 0 , ;

Is alloting more cells to the variable not guaranteed to extend the block of memory contiguously because create can only be called once per word?

Example:

create test 1 , 2 , test 3 , 4 , 5 , <<<< This won't necessarily extend the array contiguously, correct?

Are my assumptions correct?

Upvotes: 3

Views: 373

Answers (1)

Lars Brinkhoff
Lars Brinkhoff

Reputation: 14325

  • The wording in the standard gives VARIABLE and CREATE freedom to put the data in different memory regions. If they do, obviously CREATE or ALLOT can't extend the region created by VARIABLE.

  • CREATE can be called many times from any word.

  • Your example may not quite do what you think. The second line calls test, leaving its address on the stack. Then it lays down three cells which do extend the region allocated for test.

  • Your assumption about the definition of VARIABLE is not correct for all implementations.

Upvotes: 7

Related Questions