Omikron BASIC for Apple Power Mac

7-1. The VT52 Emulator Contents | 7-3. Table of MIDI Notes

 

Chapter 7-2

Memory Organization in Omikron Basic

 Memory Organization
 Application Heap
 Block Storage Section (BSS)
 Data Section


Memory Organization:

Application Heap

The application heap is a memory area assigned to the program by the operating system. For example, if a common block is requested using the MEMORY command, this block is then taken from the application heap.

Furthermore, there are a variety of operating system functions, which allocate memory blocks in the application heap. Even if the user does not utilize any MAC OS commands in the program, such memory requests may occur nevertheless, because various Omikron Basic commands are converted to MAC_OS calls.

The buffer memory of the Omikron Basic output window is set up in the application heap as well. The required memory for this case is calculated as follows: memory for output windows = width * height * color planes/8+ 1024. If output windows are utilized, the application heap should be set the to the calculated size at least with an additional minimum amount of 65 KB for the operating system.

It is possible to determine the size of the application heap already during compilation time using the two compiler control words COMPILER "MIN_SIZE X" and COMPILER "PRE_SIZE X". In the first case, X determines the amount of minimum memory required to run the program and in the second case, how much memory the program would prefer to have at its disposition.

The value specified with PRE_SIZE is given to the program if enough free memory is available; otherwise, less memory is assigned. If even the amount of memory indicated in MIN_SIZE is not available, the program start is aborted and an error message is issued.

Note: Both quantities can also be changed subsequently by selecting the program icon and then clicking on 'Get Info' in the finder.

Block Storage Section (BSS)

The stack managed by Omikron Basic is located at the upper end of the BSS. It is mainly used to store local variables. Sixteen kilobytes are generally sufficient for the stack. However, if recursive procedures or function calls with a large interleaf depths are used, more memory ought to be reserved for the stack in order to avoid the danger of the stack extending into the garbage area.

The SORT command requires greater amounts of memory on the stack as well. If this command is required for the sorting of larger fields, it would definitely be best to increase the amount of reserved stack memory. The compiler control word COMPILER "STACK X" serves for this purpose, with X specifying the desired stack size.

The areas of garbage, string heap, and arrays are located below the stack. This causes the limits between these areas to be dynamically managed by Omikron Basic. For example, if more space is needed in the array area because of a DIM command, the string heap is pushed upwards and the garbage area is thus reduced. The compiler cannot calculate how much space it must allocate for these three areas since at the time of compilation, the dimensioning of the fields, how many strings the program will create at run time and the length of each individual string are still unknowns. For this reason, a value must be pre-set using the compiler control word COMPILER "BAS_MEM X".

In order to estimate which value is to be inserted for X, here are some notes:

1. The size requirements of numerical arrays is calculated according to the amount of contained elements multiplied by the number of bytes required by the data type (bit=1/8 byte, byte=1 byte, short integer=2 bytes, long integer=4 bytes, single float=4 bytes and double float=8 bytes). An additional minimum of 16 bytes of management information for the field is added.

2. Eight bytes per field element are to be selected for the string fields. The length of the actual string rounded up to a number divisible by 8 and multiplied by 2 and an additional 8 bytes management per string are added as well. Of course, if enough memory is available, it is no problem to multiply the result by 2 or 3.

3. The garbage area is used in order to set up temporary strings. For example, in case of a string addition, the result is first collected in the garbage area and only then assigned to a string variable. Matrix operations also require memory in the garbage area. In this case, a field of the used size must fit into the garbage area once.

Another block is located below the arrays, which is used by Omikron Basic to manage internal issues.


Data Section

That data section contains such items as the TOC (Table of Contents) and the constants used in the program. The data section is managed by Omikron Basic internally and has nothing to do with the DATA command.

7-1. The VT52 Emulator Contents | 7-3. Table of MIDI Notes

Tech-Support | Order | Start | Home: http://www.berkhan.com


© 1997-2001 Berkhan-Software