TERRA Datentechnik, Technical Support Sheet
======================================================================

TZ-920512.1/BJ
M2
4.0
Large memory model in Windows environment

Related files: Supportdisk:    \HINTS\WINLARGE.ZIP
               Mailbox    :    SIG M2V4:  WINLARGE.ZIP
               
Using large/mixed memory model for data in Windows environment with
Logitech Modula-2 4.0
-------------------------------------------------------------------

A Windows application, like a non Windows DOS application, may have
one or more code and one or more data segments. The memory model,
which you specify when you compile your source modules, determines
whether compiler-generated instructions use near or far addresses.

There is one memory model, large (/CODE:L/DATA:L), for compiling a
module that generates far addresses for both code and data references.
In the large memory model each module can have up to 64K data. This
allows to have large datastructures in program without affecting the
rare space in the automatic data segment (DGROUP).

Generally, it is best to use the small or medium (Compiler default) model
for Windows applications. Under the basic and EMS memory configurations,
using the large model requires far data segments to be fixed in memory;
this constrains Window's memory management. The far data segments must
be fixed because Windows provides no mechanisms for redirecting references
to far data segments as they move in memory. However, Windows does
provide mechanisms for redirecting references to an application's auto-
matic data segment and code segments as they move. Also, if a module
is compiled with the large memory model, its data segments are always
fixed in real mode, and in all modes Windows will be able to load
only one instance of the module.

Thus it is strongly recommended NOT to use the large data model for
Windows applications. However, if you want/need to use it you should
hare in mind the following rules. 

- Compile at least the main module of your program in the medium
  data model (/DATA:M). Use for that module the "/WIN:A" switch too.

- Use the "/WIN:A" switch only for modules which are in the medium
  data model since "/WIN:A" will generate the Windows procedure prolog 
  and epilog which assumes that DS points to the automatic data segement 
  (DGROUP). Therefore, the code which should set DS to the data segment 
  of this module will not be generated. The global data of this module
  cannot be accessed. Even worse, the write access to the wrong data 
  segment will wipe out some other datastructure like the stack or 
  other elements in DGROUP.
  Note: The default project file for Windows projects does globally
        set the compiler switch "/WIN:A". You should disable this
        and set the this switch and the model switch by means of
        source embedded compiler options. 
  
- Be aware of the stacktest bug in modules compiled with "/DATA:L".
  Therefore your should combine this switch always with "/NOCHECK:S"
  (Stacktest off).

- Please see the example project "WINLARGE.MOD" in the file "WINLARGE.ZIP"
  for more information.