version 1.211, 2010/03/07 20:31:53
|
version 1.212, 2010/03/07 21:09:38
|
Line 2369 create v2 20 cells allot
|
Line 2369 create v2 20 cells allot
|
v2 20 cells dump |
v2 20 cells dump |
@end example |
@end example |
|
|
creates a word @code{v2} and reserves 20 uninitialized cells; the |
creates a variable-like word @code{v2} and reserves 20 uninitialized |
address pushed by @code{v2} points to the start of these 20 cells. |
cells; the address pushed by @code{v2} points to the start of these 20 |
You can use address arithmetic to access these cells: |
cells (@pxref{CREATE}). You can use address arithmetic to access |
|
these cells: |
|
|
@example |
@example |
3 v2 5 cells + ! |
3 v2 5 cells + ! |
Line 2421 Note that you cannot do this if you have
|
Line 2422 Note that you cannot do this if you have
|
meantime (because then your @code{allot}ed memory is no longer on the |
meantime (because then your @code{allot}ed memory is no longer on the |
top of the dictionary ``stack''). |
top of the dictionary ``stack''). |
|
|
Revisiting the @code{create} examples, where does @code{allot} get the |
|
address from? It is the current dictinary pointer, that you can read |
|
with @code{here}. And the @code{create}d word produces exactly that |
|
address (but keeps it): |
|
|
|
@example |
|
create v2a here . v2a . |
|
20 cells allot here . v2a . |
|
@end example |
|
|
|
Alternatively, you can use @code{allocate} and @code{free} which allow |
Alternatively, you can use @code{allocate} and @code{free} which allow |
freeing memory in any order: |
freeing memory in any order: |
|
|