13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

(if any). In the 64K system it contains all the executing P-code as well. Hereis an example of the use of MEMA VAIL:TYPE BIGGIE= ARRAY [0 .. 99, 0 .. 121 OF INTEGER;VAR PTR : ABIGGIE;IF MEMAVAIL > CSIZEOF CBIGGIE> DIV 2) THENNEW CPTR)ELSEWRITELN C'Help');This program fragment creates a pointer variable PTR with the base typeBIGGIE, a large array. Before executing NEW (PTR), which would allocatememory for a dynamic variable of type BIGGIE, it compares the amount ofmemory available with the size of BIGGIE. It executes NEW only if there isenough room. Note that the SIZEOF function must be used on the base typeof PTR; it cannot measure a dynamic variable such as PTR ~ . Applied toPTR itself it would return the size of the pointer type, which is 2 bytes.SIZEOF is described under "Byte Operations" in Chapter 6.Be Careful: Don't multiply MEMA VAIL to convert its value to bytes. Itsvalue may be in the upper half of the positive integer range; multiplying itby 2 can cause an integer overflow, returning an apparent negative value.In the example above, we divide the value returned by SIZEOF by 2; thisconverts it from bytes to words so it can be compared with the wordcount returned by MEMA VAIL.MARK and RELEASEWhen a program creates dynamic variables, using NEW, it starts from thebeginning of a memory area called the heap. It places dynamic variablesend to end in this area until the available memory is used up. The heap isdiscussed in Part IV of this <strong>manual</strong>, Chapter 3.At any point in this process you can flag a memory location, using theMARK procedure. If you later execute a RELEASE procedure, all thememory back to the MARK location is freed for storage of new dynamicvariables. In effect, RELEASE makes the point at which new dynamicvariables are added to memory drop back to the place flagged by MARK.III-68Chapter 5: Dynamic Variables

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!