在早期的pc机时代,电脑的硬件只支持1M字节的寻址空间。那时候,硬盘都
是奢侈品。操作系统在软盘上运作。那是pctools和hdcopy纵横江湖的时代。
那个时候主打的操作系统dos因受硬件限制也只能管理最多1M字节的连续内存
空间。在这1M内存中,又只有640K被留给应用程序使用,它们被称为常规内
存或基本内存,其它384K被称为高端内存,是留给视频显示和BIOS等使用的。
在1982年,640K内存对微型计算机来说显得绰绰有余,人们甚至认为,640K
的内存可以用来干任何事。现在看起来有些可笑,但在当时,情况确实如此。
可时代发展到今天,个人电脑上的内存动辄以数百mb计算。然道,我们使用
dos还要受限于所谓的640k内存限制吗?我们可以说不。我们可以通过一定的
内存管理工具来使用大内存。其实在win95时代这个问题就已经北MS解决得很
不错了在DOS下,系统中存在以下四种内存:
常规内存(Conventional Memory);
高端内存(Upper Memory);
扩充内存(Expanded Memory);
扩展内存(Extended Memory)。
常规内存指的是0-640K的内存区。在DOS下,一般的应用程序只能使用系统的
常规内存,因而都要受到640KB内存的限制。而且由于DOS本身和config.sys文
件中的安装的设备驱动程序和autoexec.bat文件中执行的内存驻留程序都要占
用一些常规内存,所以应用程序能使用的常规内存是不到640K的。有很多时候
我们都要想方设法地整理内存,好为一些“胃口”比较大的应用程序留出足够
的常规内存,这一点想必是许多DOS时代的电脑爱好者最熟悉不过的了。
高端内存是指位于常规内存之上的384K内存。程序一般不能使用这个内存区域,
但是EMM386.exe可以激活高端内存的一部分,并且它允许用户将某些设备驱动
程序和用户程序用Devicehigh或LH(即loadhigh)装入高端内存。dos=high,umb
也是把DOS的一部分装到高端内存里。这里的umb是高端内存块(Upper Memory
Block)的缩写。
扩充内存是一种早期的增加内存的标准,最多可扩充到32M。使用扩充内存必
须在计算机中安装专门的扩充内存板,而且还要安装管理扩充内存板的管理程
序。由于扩充内存是在扩展内存之前推出的,所以大多数程序都被设计成能使
用扩充内存,而不能使用扩展内存。由于扩充内存使用起来比较麻烦,所以在
扩展内存出现后不久就被淘汰了。
扩展内存只能用在80286或更高档次的机器上,目前几乎所有使用DOS的机器上
超过1M的内存都是扩展内存。扩展内存同样不能被DOS直接使用,DOS5.0以后提
供了Himem.sys这个扩展内存管理程序,我们可以通过它来管理扩展内存。
emm386.exe可以把扩展内存(XMS)仿真成扩充内存(EMS),以满足一些要求使用
扩充内存的程序。
最后再强调一下,不管扩充内存或扩展内存有多大,DOS的应用程序只能在常规
内存下运行。有的程序可以通过DOS扩展器(比如DOS4GW.exe等程序)使CPU进入
保护模式,从而直接访问扩展内存;但是要注意,进入保护模式以后,计算机就
脱离了DOS状态。
在dos下如何获得更多的常规内存呢?前文我们提到DOS环境下的大部分程序都是
在常规内存中运行,如果某个程序由于内存不够而运行失败,最常见的问题就是
常规内存不够。所以我们今天介绍几种尽量释放常规内存的方法:
一、当系统配置有扩展内存时,可以将DOS的大部分代码和Command.com的暂驻内存部
分安装在高内存区(HMA)。 这要求在config.sys中包含有下述命令:
device=Himem.sys
dos=high
虽然Himem.sys本身也要占用少量的常规内存,但可以使用HMA将为我们节省出更
多的常规内存。而且在msdos7 以上的版本中我们可以用devicehigh=himem.sys
将Himem.sys放置在高端内存区。有关dos这个config文件中的特殊命令我们已经
在前面讲了。这里就简单的讲讲Himem.sys。
Himem.sys管理扩充内存和高端内存(HMA)的使用。通过device命令在config文
件里配置这个设备驱动程序。如果我们使用扩充内存和高端内存,那麽安装
Himem.sys的device命令必须先于任何其他驱动的安装。
其命令一般格式为:
device=Himem.sys /选项
选项:
hmamin=0到63的整数,缺省值为0
改选项指定Himem.sys使用HMA(高内存区)之前,dos必须使用的常规内存量。
以KB为单位。
numhandles=1到128之间的整数,缺省值为32
该选项指定dos最大可以同时使用的EMB(扩充内存块)柄的数目。每个柄要占用
6字节常规内存。
int15=64到65535的整数,缺省值为0
该选项指定15h中断口分配的扩充内存大小。为了保证足够内存可用这个值必须
大于64。
machine:相应a20处理器的代码。(这个选项我也不是很清楚)
a20处理器是能够存取高内存区的一种微机部件.
a20 control:on/off
该选项指定Himem.sys是否获得a20处理器的控制权。缺省值为on。
shadowram:on/off
该选项指定Himem.sys是否关闭ROM(只读存取器)的RAM(随机存取器)部分。
cpuclock:on/off
该选项用于指定Himem.sys是否影响cpu的时钟速度。
dos在同一时刻只允许一个程序使用高内存区。如果我们不指定/hmamin=xxx那
么Himem.sys为第一个需要它的程序保留HMA。
ram 就是常规意义的内存我们现在用的!
rom 说白了就是bios用的一块用特殊方法擦写的内存.在这讲了真实模式和安全模
式还有V86模式!及其寻址的方法!
0~~640叫主内存或者是传统内存!
640~~1024叫上层内存!
1024以上叫延伸内存!
1024~~1088叫高层内存!
传统内存!
dos开机的时候会占用56k左右的内存!其他的579k是给用户使用的!当然我们可
以用其他的软件来使用打于640k的内存!要我现在的双通道ddr怎么混呀!
上层内存
这块空尖保留给bios和硬件介面使用!这384k内存是附在显卡的video rom;
video ram 以及一些控制卡上的?!应用程序不能直接存取这一区域的资料!这
就是电脑有640k内存限制的原因!应用程序只能使用传统内存!其次:上层内存
有160k每有使用!单色显示器还可以使用更多(>160k)通过管理程序可以使用!
这个地方就是如是大师所说的(upper memory blocks)简称umb!是80386以后机
器可以用的内存!
延伸内存
位于2 的20 次方以上超过8086定址范围所以在80286以后的机器才能用!
由于dos只能管理640k的内存所以必须通过符合xms的规范的延伸内存管理程序才
可以间接管理这块区域的内容!
xms是 intel; louts; ms; ast4 家共同拟定的延伸内存管理程序规定了在确定内
存存取延伸内存hma及上层内存的标准界面,目的在于避免程序间随意存取这块区
域造成冲突!himem.sys和emm386.exe等都符合!…也就是说我们只能用这样的软
件来管理延伸内存!
二、在这里我强调一下config.sys和autoexec.bat文件的内容一定要精简,不启动
那些不必要的内存驻留程序,这些内存驻留程序往往占用很多常规内存。再一个
原因就是没有像wengier那样娴熟的技巧 ,这两个文件简明一点,会减少出错的
机会。而且也便于修改,我经常看wengier的配置就看得眼花缭乱。
如果config.sys文件中含有安装缓存程序如smartdrv.exe或PC-CACHE.COM再就是
ramdrive.sys;xmsdsk.exe等虚拟盘命令,可以取消它们以节省常规内存。特别是
smartdrv.exe要使用大量的常规内存。所以wengier说PC-CACHE.COM好些。如果一
定要使用ramdrive.sys,应保证RAM盘建在扩展内存中,而不是在常规内存中。当
然最好是用xmsdsk,因为它会将自己也放入xms中。
如果config.sys文件含有buffers命令,应减少buffers指定的磁盘缓冲区数目,
每一个缓冲区会占用532个字节的常规内存。但是过多地减少盘缓冲区的个数会造
成一些程序不能正常运行,一般buffers不宜小于15。这个在前面已经讲过,这里
再重申一下。 如果config.sys文件中包含lastdriver命令,取消该命令或将
lastdriver设小一点,而不要设成astdriver=32之类。因为DOS为每个允许访问
的逻辑驱动器在内存中建立一个对应的管理块CDS,每个CDS大约占用80多个字节
的常规内存。
config.sys文件中的device和devicehigh命令的次序是很重要的,它将影响内存
的有效使用和config.sys启动时的一系列程序的正确运行。在config.sys文件中
最好按以下次序安装设备驱动程序:
1. Himem.sys;
2. 使用扩展内存的设备驱动程序;
3. emm386.exe,如果使用emm386仿真扩充内存并提供对高内存块(UMBs)的存取功
能,那么EMM386命令行应包括RAM开关而不用NOEMS。NOEMS禁止emm386.exe仿真
扩充内存,但它为安装设备驱动程序和运行其它程序提供最大的可用高内存块。
4. 使用扩充内存的的设备驱动程序;
5. 使用高内存块(UMBs)的设备驱动程序。
对于autoexec.bat,我的建议还是精简:去掉用户不需要的那些内存驻留程序;
如果不在命令行使用鼠标,不要安装任何鼠标设备驱动程序,比如mouse.com
因为可以在任何时候键入mouse.com以使用鼠标。其他有些类似程序也一样。
尽可能地在高端内存区(UMB)中安装设备驱动程序和运行其它的tsr(内存驻留)
程序。 也就是说只要能用high就坚决要用。autoexec文件里加载程序也请尽量
使用LH命令。(完)
---------------------------------------------------------------------------------------------------------------
In the early PC era, computer hardware only supported a 1M-byte addressing space. At that time, hard drives were all luxuries. The operating system operated on floppy disks. It was an era when PCTools and HDCopy ruled the roost. At that time, the main operating system, DOS, was also limited by hardware and could only manage a continuous memory space of up to 1M bytes. Among these 1M bytes of memory, only 640K was left for application programs, which were called conventional memory or base memory. The other 384K was called upper memory, which was reserved for video display, BIOS, etc. In 1982, 640K of memory was more than enough for microcomputers, and people even thought that 640K of memory could be used to do anything. Now it seems a bit funny, but at that time, that was indeed the case. But as times have developed to today, the memory on personal computers is often measured in hundreds of MB. So, do we still have to be limited by the so-called 640K memory limit when using DOS? We can say no. We can use large memory through certain memory management tools. In fact, this problem was well solved by MS in the Windows 95 era. In DOS, there are the following four types of memory in the system:
Conventional Memory;
Upper Memory;
Expanded Memory;
Extended Memory.
Conventional memory refers to the memory area from 0 to 640K. In DOS, general application programs can only use the system's conventional memory, so they are all limited by 640KB of memory. Moreover, because DOS itself and the device drivers installed in the config.sys file and the memory-resident programs executed in the autoexec.bat file all occupy some conventional memory, the conventional memory that application programs can use is less than 640K. There are many times when we have to try every means to organize memory to leave enough conventional memory for some applications with a relatively large "appetite", which I think is most familiar to many computer enthusiasts in the DOS era.
Upper memory refers to the 384K of memory above conventional memory. Programs generally cannot use this memory area, but EMM386.exe can activate part of the upper memory, and it allows users to load some device drivers and user programs into the upper memory using Devicehigh or LH (that is, loadhigh). dos=high,umb also loads part of DOS into the upper memory. Here, umb is the abbreviation of Upper Memory Block.
Expanded memory is an early standard for increasing memory, and it can be expanded up to 32M at most. To use expanded memory, a special expanded memory board must be installed in the computer, and a management program for the expanded memory board must also be installed. Since expanded memory was introduced before extended memory, most programs are designed to be able to use expanded memory but not extended memory. Since expanded memory is more troublesome to use, it was eliminated soon after extended memory appeared.
Extended memory can only be used on 80286 or higher-end machines. Currently, almost all machines using DOS with more than 1M of memory are extended memory. Extended memory cannot be directly used by DOS either. After DOS 5.0, Himem.sys, an extended memory management program, is provided, and we can manage extended memory through it. EMM386.exe can simulate extended memory (XMS) as expanded memory (EMS) to meet the needs of some programs that require the use of expanded memory.
Finally, it is emphasized again that no matter how large expanded memory or extended memory is, DOS application programs can only run under conventional memory. Some programs can make the CPU enter protected mode through a DOS extender (such as DOS4GW.exe and other programs), so as to directly access extended memory; but it should be noted that after entering protected mode, the computer is out of the DOS state.
How to obtain more conventional memory under DOS? As mentioned earlier, most programs in the DOS environment run in conventional memory. If a program fails to run due to insufficient memory, the most common problem is insufficient conventional memory. So today we introduce several methods to try to free up conventional memory:
1. When the system is configured with extended memory, most of the code of DOS and the resident memory part of Command.com can be installed in the high memory area (HMA). This requires including the following commands in config.sys:
device=Himem.sys
dos=high
Although Himem.sys itself also occupies a small amount of conventional memory, using HMA can save us more conventional memory. And in versions above msdos7, we can use devicehigh=himem.sys to place Himem.sys in the upper memory area. We have already talked about this special command in the config file of DOS earlier. Here, we will briefly talk about Himem.sys.
Himem.sys manages the use of expanded memory and upper memory (HMA). Configure this device driver in the config file through the device command. If we use expanded memory and upper memory, then the device command for installing Himem.sys must be prior to the installation of any other drivers.
Its general command format is:
device=Himem.sys /option
Option:
hmamin=an integer from 0 to 63, the default value is 0
This option specifies the amount of conventional memory that DOS must use before Himem.sys uses HMA (high memory area). Measured in KB.
numhandles=an integer between 1 and 128, the default value is 32
This option specifies the maximum number of EMB (expanded memory block) handles that DOS can use at the same time. Each handle occupies 6 bytes of conventional memory.
int15=an integer from 64 to 65535, the default value is 0
This option specifies the size of expanded memory allocated by the 15h interrupt port. This value must be greater than 64 to ensure sufficient available memory.
machine: The code corresponding to the a20 processor. (I am not very clear about this option)
The a20 processor is a microcomputer component that can access the high memory area.
a20 control:on/off
This option specifies whether Himem.sys gains control of the a20 processor. The default value is on.
shadowram:on/off
This option specifies whether Himem.sys turns off the RAM part of the ROM (read-only memory).
cpuclock:on/off
This option is used to specify whether Himem.sys affects the clock speed of the CPU.
DOS only allows one program to use the high memory area at the same time. If we do not specify /hmamin=xxx, then Himem.sys reserves HMA for the first program that needs it.
RAM is conventional memory that we use now!
ROM, to put it simply, is a piece of memory used by BIOS that is erased and written in a special way. Here, real mode, safe mode, and V86 mode are talked about! And their addressing methods!
0~~640 is called main memory or traditional memory!
640~~1024 is called upper memory!
Above 1024 is called extended memory!
1024~~1088 is called high memory!
Traditional memory!
When DOS starts up, it occupies about 56K of memory! The other 579K is for users to use! Of course, we can use other software to use memory larger than 640K! How can my current dual-channel DDR mix!
Upper memory
This space is reserved for BIOS and hardware interfaces! This 384K of memory is attached to the video rom of the graphics card; video ram and some control cards?! Application programs cannot directly access the data in this area! This is the reason why the computer has a 640K memory limit! Application programs can only use traditional memory! Secondly, 160K of the upper memory is not used! Monochrome monitors can also use more (>160K) and can be used through management programs! This place is what the master said (upper memory blocks) referred to as umb! It is memory that can be used on machines after 80386!
Extended memory
It is located above 2^20 and exceeds the addressing range of 8086, so it can only be used on machines after 80286!
Since DOS can only manage 640K of memory, it must be managed indirectly through an extended memory management program that complies with the XMS specification.
XMS is a specification for extended memory management programs jointly formulated by Intel, Lotus, MS, and AST4. It stipulates a standard interface for determining memory access to extended memory HMA and upper memory, aiming to avoid conflicts caused by random access to this area between programs! Himem.sys and EMM386.exe, etc., all comply!... That is to say, we can only use such software to manage extended memory!
2. Here I emphasize that the contents of the config.sys and autoexec.bat files must be streamlined, and unnecessary memory-resident programs should not be started. These memory-resident programs often occupy a lot of conventional memory. Another reason is that without the skill as proficient as wengier, making these two files concise will reduce the chance of errors. And it is also easy to modify. I often get confused when looking at wengier's configuration.
If the config.sys file contains installation cache programs such as smartdrv.exe or PC-CACHE.COM, as well as virtual disk commands such as ramdrive.sys; xmsdsk.exe, etc., they can be canceled to save conventional memory. Especially smartdrv.exe uses a large amount of conventional memory. So wengier said that PC-CACHE.COM is better. If ramdrive.sys must be used, ensure that the RAM disk is built in extended memory, not in conventional memory. Of course, it is best to use xmsdsk because it will also put itself into XMS.
If the config.sys file contains the buffers command, the number of disk buffers specified by buffers should be reduced. Each buffer occupies 532 bytes of conventional memory. But reducing the number of disk buffers too much will cause some programs to not run normally. Generally, buffers should not be less than 15. This has been mentioned earlier, and it is reiterated here. If the config.sys file contains the lastdriver command, cancel this command or set lastdriver smaller, and do not set it to astdriver=32 or something like that. Because DOS builds a corresponding management block CDS in memory for each logical drive allowed to be accessed, and each CDS occupies about 80 more bytes of conventional memory.
The order of the device and devicehigh commands in the config.sys file is very important, and it will affect the effective use of memory and the correct operation of a series of programs when config.sys starts. It is best to install device drivers in the following order in the config.sys file:
1. Himem.sys;
2. Device drivers that use extended memory;
3. EMM386.exe. If EMM386 is used to simulate expanded memory and provide access to high memory blocks (UMBs), then the EMM386 command line should include the RAM switch instead of NOEMS. NOEMS prohibits EMM386.exe from simulating expanded memory, but it provides the largest available high memory blocks for installing device drivers and running other programs.
4. Device drivers that use expanded memory;
5. Device drivers that use high memory blocks (UMBs).
For autoexec.bat, my suggestion is also to streamline: remove those memory-resident programs that users do not need; if the mouse is not used on the command line, do not install any mouse device drivers, such as mouse.com because the mouse can be used by typing mouse.com at any time. The same is true for some other similar programs.
Try to install device drivers and run other TSR (memory-resident) programs in the upper memory area (UMB) as much as possible. That is to say, as long as high can be used, it should be used resolutely. Please also try to use the LH command to load programs in the autoexec file. (End)
---------------------------------------------------------------------------------------------------------------