views:

235

answers:

2

what difference does it make when i choose 'large memory model' instead of 'small memory model' inside Turbo C compiler ?

how does that change behavior of my program ?

regards, essbeev.

+3  A: 

It refers to very old concept of 16-bit memory model. 32bit & 64bit computers know nothing about these memory models.

So returning to your questions: small - declares that pointers allows you address only 64k of data or code. Pointer has length 16 bit. Entire your program is resided in single 64k segment. To explicitly address another part of memory you need explicitly declare pointer as FAR. large - declares that pointer to code or data has 32 bit, so it is FAR by default.

Hope you would not hang on these questions so long, since it is obsolete concept.

Dewfy
32 and 64-bit x86 machines DO know about 16-bit memory models, but it is highly unlikely that one runs an operating system that lets you access it on those nowadays.
kusma
@kusma No, they don't. To run pure 16 bit app NT-like windows needs to start so called WoW (windows on windows). The strong difference between 16-bit and 32 bit memory model - is so called "32 bit protected mode" or flat model.
Dewfy
The machines can, otherwise you wouldn't be able to boot up, since the CPU is started in 16-bit real mode after the BIOS-screen. WoW is a pure Windows construct (see http://en.wikipedia.org/wiki/Windows_on_Windows), and happens after the CPU has been switched to 64-bit mode.The difference between flat memory model and real-mode isn't exactly what you think either. It is perfectly possible to leave a x86 CPU in 16-bit mode while entering protected mode. In fact, protected mode was added in the 286 (see http://en.wikipedia.org/wiki/Protected_mode#The_286), which is a 16-bit CPU.
kusma
@kusma: CPU is started in 16-bit - yes, but look at tricky way to start protected. You talk about protected mode of 286 - but it has lack of flat model, so FAR pointers in 286 protected still had a sence.
Dewfy
Thanks a lot to both of you..
essbeev
A: 

The 8086 processor has weird 20 bits addressing using a combination of 16 bits segment registers and 16 bits offsets. To simplify this, you could pack both in a 32 bits FAR pointer, or you could asssume a default segmet register and store just the lower 16 bits in a NEAR pointer.

The difference between the small and large models is simply whether pointers are by default NEAR or FAR if not explicitly specified.

MSalters