【求助】关于图形函数
<P>源程序如下:<br>#include <graphics.h> <br>#include <stdlib.h> <br>#include <stdio.h> <br>#include <conio.h> <br>#include <alloc.h> </P><P>void save_screen(void far *buf[4]); <br>void restore_screen(void far *buf[4]); </P>
<P>int maxx, maxy; </P>
<P>int main(void) <br>{ <br> int gdriver=DETECT, gmode, errorcode; <br> void far *ptr[4]; </P>
<P> /* auto-detect the graphics driver and mode */ <br> initgraph(&gdriver, &gmode, ""); <br> errorcode = graphresult(); /* check for any errors */ <br> if (errorcode != grOk) <br> { <br> printf("Graphics error: %s\n", grapherrormsg(errorcode)); <br> printf("Press any key to halt:"); <br> getch(); <br> exit(1); <br> } <br> maxx = getmaxx(); <br> maxy = getmaxy(); </P>
<P> /* draw an image on the screen */ <br> rectangle(0, 0, maxx, maxy); <br> line(0, 0, maxx, maxy); <br> line(0, maxy, maxx, 0); </P>
<P> save_screen(ptr); /* save the current screen */ <br> getch(); /* pause screen */ <br> cleardevice(); /* clear screen */ <br> restore_screen(ptr); /* restore the screen */ <br> getch(); /* pause screen */ </P>
<P> closegraph(); <br> return 0; <br>} </P>
<P>void save_screen(void far *buf[4]) <br>{ <br> unsigned size; <br> int ystart=0, yend, yincr, block; </P>
<P> yincr = (maxy+1) / 4; <br> yend = yincr; <br> size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </P>
<P> for (block=0; block<=3; block++) <br> { <br> if ((buf[block] = farmalloc(size)) == NULL) <br> { <br> closegraph(); <br> printf("Error: not enough heap space in save_screen().\n"); <br> exit(1); <br> } </P>
<P> getimage(0, ystart, maxx, yend, buf[block]); <br> ystart = yend + 1; <br> yend += yincr + 1; <br> } <br>} </P>
<P>void restore_screen(void far *buf[4]) <br>{ <br> int ystart=0, yend, yincr, block; </P>
<P> yincr = (maxy+1) / 4; <br> yend = yincr; </P>
<P> for (block=0; block<=3; block++) <br> { <br> putimage(0, ystart, buf[block], COPY_PUT); <br> farfree(buf[block]); <br> ystart = yend + 1; <br> yend += yincr + 1; <br> } <br>} </P>
<P>该程序的功能:将程序所画图形均分四块利用getimage()函数保存到内存中,然后利用putimage()函数将其恢复,但是运行到第三块区域的时候,就会报错,退出图形模式输出Error: not enough heap space in save_screen().,这是何故呀?<br></P>
[align=right][color=#000066][此贴子已经被作者于2007-1-22 13:03:26编辑过][/color][/align]
区域太大,存不下去了 <P>那为什么buf[0]和buf[1]能申请得到,而buf[2]就申请失败呢?</P> dos中最多可以申请多大的内存空间呀?
页:
[1]
