小型内存模型和中型内存模型有什么区别? [英] What's the difference between the small memory model and the medium memory model?

查看:106
本文介绍了小型内存模型和中型内存模型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wikipedia和其他资源描述了可用于x86平台上的编译器的不同的内存模型.实模式).

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

我可以看到微型模型和小型模型之间的差异(在微型模型中,代码,堆栈和数据段寄存器指向同一段,在小型CS指向一个段,SS和DS指向另一个段),以及小型和紧凑型之间的差异(CS,SS和DS指向三个单独的网段),但是小型和中型之间的差异使我难以理解,因为CS均指向一个网段,SS和DS指向另一个网段.

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?

推荐答案

从Turbo C ++内置帮助中(菜单:Options-> Compiler-> Code Generation ...-> Model,按F1)

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

将小型模型用于平均大小的应用程序.

Use the small model for average size applications.

代码段和数据段不同,并且不重叠,因此您有64K的代码以及64K的数据和堆栈.总是使用近指针.

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.

中等

中型模型最适合于不将大量数据存储在内存中的大型程序.

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

远指针用于代码,但不用于数据.结果,数据加堆栈的大小限制为64K,但是代码最多可以占用1MB.

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.

因此,您已经拥有了它.在中型模型中,您使用远指针访问代码(该代码具有远调用和远返回指令,并使用远函数指针进行操作),并且您可以具有多个段.标准的16位DOS .EXE文件格式支持多个段.在小型模型中,所有指针都在附近,因此您不能更改程序中的默认代码段.

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.

这篇关于小型内存模型和中型内存模型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆