13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Here is an example of this process in action:TYPE DATE = RECORDDAV, YEAR : INTEGER;MONTH : STRINGEND;{Declare a base type}VAR PTRBEGIN: "DATE;{Declare a pointer variable PTR,which will point to a dynamicvariable of type DATE}{Start body of program}•.. Program text ...NEWEND.CPTR>;... Program text ...PTR" ...PTR".VEAR ...{Create a dynamic variable oftype DATE>{Reference to dynamic variable}{Reference to field in variable}{End body of program}The space now allocated for the new dynamic variable is taken frompreviously unused memory. It is the correct size for the dynamic variable'sbase type. In the case of a variant record type, it can be either large enoughfor the largest variant, or the correct size for one specified variant. Fordetails see below, "Dynamic Variant Record Variables."Using Dynamic VariablesThe process just described may seem like a roundabout way of creating avariable. Indeed, for most data types it makes little sense. But with twotypes, arrays and records, it is an important tool for run-time memorymanagement.Sometimes you need to create a large array for temporary data storageduring program execution. If you declare such an array as a static variable,Pascal will reserve memory space for it all the time your program isrunning. That memory will never be available for other program use.By storing the array as a dynamic variable, however, you can control whenits memory space is reserved. By using the MEMA VAIL function yourprogram can measure how much unused memory is available beforeUsing Dynamic VariablesIII-63

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

Saved successfully!

Ooh no, something went wrong!