Andrew J. Brehm
Andrew J. Brehm

Reputation: 4768

What's the difference between the small memory model and the medium memory model?

Wikipedia and other resources describe different memory models available for compilers on the x86 platform (real mode).

I can see the difference between the tiny model and the small model (in tiny the code, stack and data segment register point to the same segment, in small CS points to one segment, SS and DS to another), and the difference between small and compact (CS, SS and DS point to three separate segments) but the difference between small and medium eludes me, as in both CS points to one segment and SS and DS to another.

I realise that the medium model is meant for programs that have more than one code segment but how is that difference realised? What exactly does it change?

Upvotes: 2

Views: 6922

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62106

From Turbo C++ built-in help (menu: Options->Compiler->Code Generation...->Model, press F1)

Small

Use the small model for average size applications.

The code and data segments are different and don't overlap, so you have 64K of code and 64K of data and stack. Near pointers are always used.

Medium

The medium model is best for large programs that don't keep much data in memory.

Far pointers are used for code but not for data. As a result, data plus stack are limited to 64K, but code can occupy up to 1MB.

So, there you have it. In the medium model you use far pointers to access code (the code has far call and far return instructions and manipulates with far function pointers) and you can have multiple segments. The standard 16-bit DOS .EXE file format supports multiple segments. In the small model all pointers are near and so you can't and don't change the default code segment in the program.

Upvotes: 1

Related Questions