TERRA Datentechnik                                         19-Feb-92
A. Gorrengourt
=====================================================================

Hints for Selecting the Memory Model with Logitech Modula-2 Version 4
---------------------------------------------------------------------


1. General Information
   -------------------

For a general description of the different memory models supported by
the Logitech Modula-2 Version 4 system, please refer to the section on
Memory Models in the Programmer's Guide.

For detailed information on the memory model compiler options /CODE,
/DATA and /CONSTANT, please refer to the description of the compiler
options in the Programmer's Guide.


2. Selecting the Code Memory Model
   -------------------------------

Use the default large memory model for code.

Using the small model for code is usually only possible if the
complete code of your program is smaller than 64 KB. Using the
small model requires recompilation of all library modules used.
Therefore, it is recommended to stay with the large model for
code, unless you absolutely need to minimize code size (e.g.
for a TSR). Note that mixing different code memory models in
the same program usually causes problems and cannot be done.


3. Selecting the Data and Constant Memory Model
   --------------------------------------------

Start by using the default medium model for data and constants.
When using the small memory model for data analogue restrictions
like when using the small model for code apply. Therefore, it is
recommended to stay with the medium data model as far as feasible.
      
With the medium data model, all data and constant segments are
included into the group DGROUP which has a maximum size of 64 KB.
If you receive the linker error "Group Size Exceeds 64k" this
usually indicates that the DGROUP has become too large. If this
happens, generate a map file when linking (it will be generated
despite the error) and inspect segment list at the beginning
of the map. Check which of the segments with of the classes
CONST, DATA, and BSS are very large, because these are the ones
that constitute the DGROUP. Most likely, there are only a few
very large segments. Take one of the following measures in order
to reduce the size of the DGROUP. Note that the measures are
listed in regard to best performance, i.e. the first measures
listed allow for the smallest code and the best performance.
    
(1) If you have large CONST segments, compile the corresponding
    modules with /CONSTANT:S (small model for constants), if this
    allows the remainder of the DGROUP to fit into 64 KB. If such
    measures would not be sufficient to reduce the DGROUP size
    below 64 KB, it is usually simpler/sufficient to use only measure
    (2) for some module(s). But you may also use a combination of
    measures (1) and (2).

(2) If you have large DATA or BSS segments, compile the
    corresponding modules with /DATA:L/CONSTANT:S (large model
    for data and small model for constants). Repeat this step
    until the remainder of the DGROUP fits into 64 KB.
    See also note on Stack Check Problem below.

(3) If any of the two previous measures causes the code segment
    (which now includes the constants due to the /CONSTANT:S)
    of a module to grow beyond 64 KB, compile that module with
    /CONSTANT:L (large model for constants).

Note that for best performance you should only compile the
selected modules using a different memory model for data and/or
constants. The rest of your program should still be compiled
using the default memory model for data and constants.

Note also that mixing the medium and large memory models for
data, as well as mixing the small, medium, and large memory
models for constants in a program is allowed and unproblematic.
However, you should not mix the small data memory model with
other data memory models, nor with the large constant model.

Note on Stack Check Problem when using /DATA:L (large data model):

  The compiler version 4.0 generates bad stack check code when
  used with /DATA:L (together with /CHECK or /CHECK:S).

  Workaround: Compile with stack test off. If you dislike this,
  separate the large data into a module that does not contain any
  code. Compile that new module with stack test off and /DATA:L,
  and compile the modified original module using the medium data
  model /DATA:M (default) and with stack test on.

                               * * *