| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1832 人关注过本帖
标题:[求助]大哥大姐们,本人经过快一个月的思考,还是...
只看楼主 加入收藏
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
结帖率:100%
收藏
 问题点数:0 回复次数:14 
[求助]大哥大姐们,本人经过快一个月的思考,还是...

本人几个月前就遇到过的问题.现在到了非要解决不可的地步.
去年,年未的时侯就开始编一个文本编辑器,用TC2.0作编译器.
开头以为这样的程序很简单,但在编写的过程中,出现了一些让我感到要放弃的问题.
第一个大问题就是,当我编写到大约5000行左右,就发现TC2.0也编译不了,总是说out of memory...
因为一个文件长度大约只能是64KB,我就把文件大的分散到几个文件,然后用#include""把它们包含起来,
这个时侯就不出现这样的问题了.
不过多久,当我代码编写到8000左右的时侯,又出现了这样的问题,
我又把文件大的分散到几个文件,这样做了.结果不顶用,我就郁闷了.为什么会出现这样的问题.
为了找到原因,我又把TC2.0的菜单功能全部用金山词霸翻译出来.结果发现,就是编译的模块大的原因.
我就把编译模块改成巨大的.这个时侯,out of memory...不出现了.
但是,好景不长,当我把代码编写到10000行左右,
又出现了这样的问题.这个时侯,我蒙了.怎么又出现这样的问题.我把前面的所能做的方法全部把试了.有时有用,
但再多编写几十行的代码编译一下,又出现了out of memory... .我跑到图书馆里,希望能找到一点资料,翻了许多书.
结果还是不能解决问题,回寝室在网上找,也没有找.吃饭的时侯在想,走路的时侯也在想,上课时不时地也在想.
睡觉的时侯,当然是想问题就好的时侯(每当我遇到不解的地方,常常会去睡觉,睡觉前思考遇到的问题,有时会突发奇想找到解决问题的方法.在此,我建议,当坐在电脑前想不出问题,换个地方想问题可能会突发奇想.).躺在床上想,有时想到天亮,还是想不出来.
要知道我这个人是不轻意去问别人的.除非实在没办法想不出来.我这个人有一个习惯,来判断这个问题我不能解决.那就是时间来横量,就是至少我想这个问题的时间跨度不少于15天.
但那个out of memory...的问题想了几个星期,还是想不出.发到论坛上,还是没有人愿分享.
结果,我就跑到学院里,找到大一教我C语言的老师那里,问个明白.向他说明情况后,他给了我一些建议.
其中最重要的就是:链接. 我突然明白了.我的问题所在.我谢过老师之后,立刻跑回寝室,生怕忘了我的解决方法:
因为我的程序是用#include""把全部文件串到一起编译成一个模块.这样会造成模块很大而导致编译器无法编译.
我就这么想能不能不把全部文件编译成一个模块而是几个模块.这时,我就想到了TC2.O的工程菜单.然后,我就把一些文件编译成独立的模块,再通过LINK把独立的模块LINK起来.成功了.


这是我编写这个程序遇到的第一大个问题,之前和之后还遇到了不少的问题,都被我一一解决了.

大约过了一二个月的时侯.就是程序全面功能完善的时侯,让我感到措手不及的是程序申请不到空间.


这也是我编写这个程序遇到的第二个大问题:
在Complie中的Get info可以得知可用存储器空间是265KB.而我的可执行文件的大小就是190KB再加上十多个文件产生的页面碎片.还加上5KB左右的全局变量.如果文本编辑器要写出200行的字符,还需要100KB的存储器空间,还后来的加入了汉字显示的功能,一个HZK16的汉字库大小261KB,要打开这个汉字库就需要再加上261KB的存储器空间.
总的加起来大约要用的存储器空间:470KB(而且只能写一百行的字符),但TC2.0的存储器空间只有265KB.


这个问题我快想了一个月.还没想到解决之道.希望各位大哥大姐们能给一些建议.
本人不甚感激.

[此贴子已经被作者于2007-6-13 1:39:50编辑过]

搜索更多相关主题的帖子: 大姐 思考 
2007-06-13 01:35
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 

首先,纠正你一个错误认识,TC是 16 位编程器,换而言之他编译的程式模式是在dos下运行的,能在win的cmd 运行是因为cmd模拟了dos环境.在dos下,用户可用内存是 640K(包括了dos系统占用的内存),640~1M称为高端内存,1M以上称为扩展内存.
给你一个使用扩展内存的例子:

#include <stdio.h>
#include <string.h>

/*
---------------------------------------------------------------------------
TC_XMEM.C - This is a short program to demonstrate how to use the XMEM
function in Turbo C. All it does is take one string, move it
to extended memory at location 100000 (1 megabyte boundary),
then takes it from extended memory and places it into a second
array. As you can see, we do initialize o_message to the test
string and n_message to nothing, but we never touch any of them
again until it is time to show you the results of XMEM.

In essence, this is a heck of a roundabout way to do a strcpy,
but the possibilities for applications are boundless.

There are four statements here that will generate four non-
portability warnings, particularly between memory models, but
we ignore them since we are only trying to show how XMEM works.
---------------------------------------------------------------------------
*/

unsigned s_seg, /* Source data segment */
d_seg, /* Destination segment */
s_off, /* Source offset */
d_off, /* Destination offset */
size; /* Size, in bytes, of data to transfer */

char *s_meg, /* Megabyte boundary of source, 0 to 15 */
*d_meg; /* Megabyte boundary of destination, 0 to 15 also */

/* Note that one of the two must have a value of 0 since XMEM transfers */
/* to/from DOS memory, which is below the 1 megabyte boundary */

int result; /* Holds return code from XMEM */
int CPU; /* Holds type of CPU currently in machine */
char VDISK_ON; /* Used to tell us if VDISK is alive */
unsigned long temp2; /* For our own temp purposes also */

char o_message[36]; /* The source area */
char n_message[36]; /* The destination (target) area */
char v_save[36]; /* Temp area to save VDISK boot sec */

/* This is the structure that defines the IBM PC-DOS VDISK boot record */
/* structure. Here is where we get the info to determine if VDISK is */
/* is installed and how much of extended memory has it already */
/* allocated to itself. */

typedef struct {
char jump_code[3]; /* Boot jump code, all 0's */
char vendor_id[8]; /* Should contain "VDISKx.x" */
int bytes_per_sector; /* Bytes per sector in ram disk */
char sectors_per_cluster; /* Sectors per cluster */
int reserved_sectors; /* Number of reserved sectors */
char fat_copies; /* Number of FAT copies */
int dir_entries; /* Number of root dir entries */
int num_sectors; /* Total number of sectors */
char media; /* Media descriptor bytes */
int sectors_per_fat; /* Sectors occupied by one FAT */
int sectors_per_track; /* Number of sectors per track */
int heads; /* Number of heads */
int hidden; /* Number of hidden sectors */
int em_start; /* Starting loc of 1st free area... */
/* ...in extended memory/1024 */
} vdisk_boot_sec;

vdisk_boot_sec BOOT_SEC;

/* IOADDRESS is used to set port to read/write to */
/* IODATA is used to read/write data once port is selected */

#define IOADDRESS 0x070
#define IODATA 0x071

/* These variables hold the CMOS extended memory size information */

int EXT_LO, EXT_HI, EXT_TOTAL;

main()
{

printf("TC_XMEM: Demonstration of the XMEM assembly language\n");
printf(" routine to mode data to/from extended memory\n");

CPU = CPUID();
if ((CPU != 286) && (CPU != 386))
{
result = 99;
error_handle();
}

printf("TC_XMEM: CPU is 80%d.\n",CPU);

/* Let's see how much extended memory we have, if any... */

EXT_LO = portpeek(0x017);
EXT_HI = portpeek(0x018);
EXT_TOTAL = ((EXT_HI << 8) + EXT_LO);

if (EXT_TOTAL > 0)
{
printf("TC_XMEM: %dK extended memory installed.\n",EXT_TOTAL);
printf(" Total memory is %dK.\n",(EXT_TOTAL+1024));
printf(" This includes DOS, video, reserved and extended memory.\n");
}
else
{
result = 7;
error_handle();
}

/* At this point we do a quick check of the first few bytes of extended */
/* ram to find out if VDISK is already in place. We cannot check for any */
/* other ram disks because VDISK is the only one that we have documentation */
/* for and it's the only one (that we know) that tells us where in extended */
/* memory the ram disk buffers end. */

/* Source is address 100000, location of boot record of VDISK if installed */

s_seg = s_off = 0;
s_meg = 1;

/* Destination maps into the vdisk_boot_sec structure to decode the meaning */
/* of life in the VDISK fast lane... */

d_seg = _DS; /* small/tiny memory model only! */
d_off = &BOOT_SEC.jump_code[0];
d_meg = 0;

/* Size is size of boot record in bytes, 32 bytes */

size = 32;

/* All set, bring it down and let's take a look at it! */

result = XMEM(s_seg,s_off,s_meg,d_seg,d_off,d_meg,size);

/* Check for error */

if (result > 0) error_handle();

/* No errors. First, let's see if we have a VDISK */


VDISK_ON = strstr(BOOT_SEC.vendor_id,"VDISK");
if (VDISK_ON != 0)
{
printf("TC_XMEM: VDISK is installed.\n");
printf(" VDISK buffer(s) end at %uK\n",BOOT_SEC.em_start);
if (BOOT_SEC.em_start >= (EXT_TOTAL+1024))
{
printf(" VDISK has allocated all extended memory.\n");
}
printf(" Saving VDISK Boot Record.\n");
d_off = &v_save;
size = 36;
result = XMEM(s_seg,s_off,s_meg,d_seg,d_off,d_meg,size);
}

strcpy(o_message,"This is a test of the XMEM function.");
strcpy(n_message,"\0x00");

printf("TC_XMEM: Source and target initialized.\n");
printf(" Source area contains:\n");
printf(" [ %s ]\n",o_message);
printf(" Target area contains:\n");
printf(" [ %s ]\n",n_message);

/* Since we are working with the small memory model here, we know that the */
/* source string data is located in segment _DATA, which is grouped under */
/* DGROUP, whose value is in the DS: segment. For other memory models, you */
/* must decode any "far" pointers to determine what segment the source */
/* is located in. */

s_seg = _DS; /* tiny/small memory model only! */

/* source offset is the address of o_message (tiny,small memory models) */

s_off = &o_message;

/* Source is in DOS memory */

s_meg = 0;

/* Destination setup, move string to address 10000:0 */

d_seg = d_off = 0;
d_meg = 1;

/* Transferring 36 bytes, length of string */

size = 36;

/* Setup completed, call XMEM and send the string to extended memory */
/* storage. */

result = XMEM(s_seg,s_off,s_meg,d_seg,d_off,d_meg,size);

/* Check to see if any errors detected. */

if (result > 0) error_handle();

/* No errors, say so */

printf("TC_XMEM: Move from low to high mem successful.\n");

/* Ok, now we set source to 100000, where data is now stored, and target */
/* to the location where we have allocated space for the string */

s_seg = s_off = 0;
s_meg = 1;
d_seg = _DS; /* tiny/small memory model only! */
d_off = &n_message;
d_meg = 0;

/* Heads up, data coming down! */

result = XMEM(s_seg,s_off,s_meg,d_seg,d_off,d_meg,size);

/* Check to see if we have any errors */

if (result > 0) error_handle();

/* Everything seems ok, say so, then print both strings to prove that */
/* we actually copied the data */

printf("TC_XMEM: Move from high to low mem successful.\n");
printf(" Source area contains:\n");
printf(" [ %s ]\n",o_message);
printf(" Target area contains:\n");
printf(" [ %s ]\n",n_message);

/* If VDISK is installed we now have to restore the boot sector in */
/* extended RAM so as to keep everything in working condition... */

if (VDISK_ON != 0)
{
printf(" Restoring VDISK Boot Sector.\n");
s_seg = _DS;
s_meg = 0;
s_off = &v_save;
d_seg = d_off = 0;
d_meg = 1;
size = 36;
result = XMEM(s_seg,s_off,s_meg,d_seg,d_off,d_meg,size);
if (result > 0) error_handle();
}

printf("TC_XMEM: Done.\n");

exit(0);
}

/* This is our error handler */

error_handle()
{
printf("\aERROR : ");
switch (result)
{
case 1 : printf("Memory parity error.\n");
break;
case 2 : printf("Exception interrupt error.\n");
break;
case 3 : printf("8042 slave CPU error.\n");
break;
case 5 : printf("Programming error, bounds.\n");
break;
case 6 : printf("Not enough extended memory available.\n");
break;
case 7 : printf("No extended memory installed.\n");
break;
case 99: printf("Program needs 80286 or 80386 CPU.\n");
break;
default: printf("Unknown error.\n");
}
exit(result);
}

/* ------------------------------------------------------------------- */
/* This routine returns the current value in CMOS ram for the location */
/* passed to the function in the variable "location". */
/* ------------------------------------------------------------------- */

portpeek(location)
unsigned int location;
{
outportb(IOADDRESS,location);
return(inportb(IODATA));
}


九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2007-06-13 13:13
老糊涂
Rank: 1
等 级:新手上路
威 望:1
帖 子:117
专家分:0
注 册:2007-5-19
收藏
得分:0 

虽然不能帮LZ解决问题,但是还是出LZ的文章中学到了不少的东西


2007-06-13 13:35
QQ395108605
Rank: 1
等 级:新手上路
帖 子:194
专家分:0
注 册:2006-11-29
收藏
得分:0 

学习了~


学海无崖~!
2007-06-13 13:54
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
以下是引用neverTheSame在2007-6-13 1:35:26的发言:

这也是我编写这个程序遇到的第二个大问题:
在Complie中的Get info可以得知可用存储器空间是265KB.而我的可执行文件的大小就是190KB再加上十多个文件产生的页面碎片.还加上5KB左右的全局变量.如果文本编辑器要写出200行的字符,还需要100KB的存储器空间,还后来的加入了汉字显示的功能,一个HZK16的汉字库大小261KB,要打开这个汉字库就需要再加上261KB的存储器空间.
总的加起来大约要用的存储器空间:470KB(而且只能写一百行的字符),但TC2.0的存储器空间只有265KB.

給你提供几点参考意见:
1。TC2.0除了tc.exe还有个tcc.exe,你应该用后者对你编写出来的程序进行编译
和连接。这样生成的exe文件是在dos平台上独立运行的,不再需要tc那种集成开发环
境,因而节省出来毛200KB空间!!!
2。如果使用UCDOS6.0的汉字系统,则它的汉字库也可以做到不占用基本内存。如此
你面临的窘境也就彻底化解了。
3。为何不使用VC6.0环境呢?它可以使用的内存不再受该死的640KB限制。

2007-06-13 14:17
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
顺告:
Win98系统的pdos95汉字库
好像也不占用基本内存。
2007-06-13 16:45
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
谢谢楼上,你是我的大恩人啊.
我会照你说的去做的.

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-06-13 17:13
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
回复:(Knocker)首先,纠正你一个错误认识,TC是 16 位...
谢谢你的内存扩展的例子.
我会认真看研究你的算法的.

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-06-13 17:15
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
收藏
得分:0 
楼主的程序也很大哦.
不知道vc的限制是多少呢?

人生重要的不是所站的位置,而是所朝的方向
2007-06-13 18:01
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
这个程序我做了大约快半年了.

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2007-06-13 18:04
快速回复:[求助]大哥大姐们,本人经过快一个月的思考,还是...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017566 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved