Garbage collection – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual
Page 113
![background image](https://www.manualsdir.com/files/797818/content/doc113.png)
8K. Other Languages
II. SOFTWARE GUIDES - 8. Driver488/DRV
II-98
Personal488 User’s Manual, Rev. 3.0
Other types of BASICs include a function called
VARSEG
that returns the segment address of a variable.
This eliminates the need for a special assembly-language routine, but, in these languages, the segment
address may be different for each variable or array.
VARSEG
may need to be called for each variable
whose address is required.
Note that the address (
segment
and
offset
) of a variable or array may not be the address of the
portion of that variable that holds the data. The address may instead be the address of a variable
descriptor, a data structure that describes the structure of the variable or array. The descriptor usually
includes the current length of the variable as well as its actual address. The descriptor of an array may
include the number of elements in the array, the number of subscripts used to refer to the array
elements, and the ranges of the subscripts. You should check with the language manufacturer to
determine just what
VARPTR
(or its equivalent) points to. When trying to determine addresses you may
have to consider garbage collection, memory models, and calling protocols.
Garbage Collection
Garbage collection is a process whereby a language with variable-length data structures, such as strings
in BASIC or lists in LISP, can reuse the memory that is no longer being used by any variables. When a
program is running, it can move variables around to consolidate this unused space and reclaim it for
new variables. Garbage collection can occur at almost any time and invalidate any stored values of
variable addresses. Thus, in languages that use garbage collection, addresses should be “fresh” and
recalculated whenever they might have changed.
Memory Models
Some languages, most notably C, allow a choice of memory models. These are known by various
names such as: “tiny,” “small,” “medium,” “compact,” “large,” or even “huge.” The exact meaning of
these names may vary between different languages, but they typically have the following interpretation:
When using the Tiny, Small, or Medium memory models, all data elements are in the same
segment
.
Once the segment address of one is known, it can be used to refer to any address. In the Compact,
Large, and Huge memory models, data elements have a 32-bit address composed of a
segment
and an
offset
. The segment values may be different for each data element.
Many languages do not offer the same flexibility of memory models as does C, but addressing methods
used by other languages may often be viewed as one of the standard C models.
The following program fragment, taken from the Microsoft C support file
IEEEIO.C
shows how
segment
and
offset
addresses are computed in the various memory models:
Memory
Model
Total
Code/Data
Largest Data
Structure
Typical Interpretation
Tiny
≤ 64K bytes
≤ 64K bytes
Code and data fit together within a single 64K segment.
Might be in the format necessary to convert to a
.COM
file.
Small
≤ 64K bytes
≤ 64K bytes
Both code and data each reside within their own 64K
segment. Near (16-bit, offset only) references to
code and data elements are possible.
Medium
> 64K bytes
(for code only)
≤ 64K bytes
(for data only)
≤ 64K bytes
More than 64K of code, in multiple segments, while
data fits within a single 64K segment. No
subprogram may exceed 64K.
Compact
≤ 64K bytes
(for code only)
> 64K bytes
(for data only)
≤ 64K bytes
Code fits within a single 64K segment, while data may
occupy more than one segment. Explicit segment
addresses are required to address data elements. No
single data structure, such as an array or record,
may be more than 64K.
Large
> 64K bytes
≤ 64K bytes
More than 64K of both code and data. Still, no single
subprogram or data structure may exceed 64K.
Huge
> 64K bytes
> 64K bytes
More than 64K of both code and data. Data structures
may be larger than 64K.