I'm using Turbo C++ 3.0 on win98 to make some graphics.
But after I have run the kode once, I can't do it again.
The compiler says "Out of memory".
The heap is put at 640 K.
I guess it my code, but I can't seem to find the error in the code
Can anybody help me ??
Gugge
--------------clip
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
void save_screen(int x, int y, void far *buf[4]);
void restore_screen(int x, int y, void far *buf[4]);
int main(void)
{
int gdriver=DETECT, gmode, errorcode;
void far *ptr[1];
/* auto-detect the graphics driver and mode */
initgraph(&gdriver, &gmode, "C:\\BC\\BGI");
errorcode = graphresult(); /* check for any errors */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/* draw an image on the screen */
rectangle(0, 0, 639, 479);
line(0, 0, 639, 479);
line(0, 479, 639, 0);
getch();
save_screen(300,240,ptr); /* save the current screen */
line(100,100,300,300);
outtextxy(200,400,"HEJ MOR");
setcolor(RED);
line(200,333,400,100);
getch();
cleardevice(); /* clear screen */
restore_screen(300,240,ptr); /* restore the screen */
getch(); /* pause screen */
closegraph();
return 0;
}
void save_screen(int x, int y, void far *buf[1])
{
unsigned size;
size = imagesize(0, 0, 50, 50);
/* get byte size of image */
if ((buf[0] = farmalloc(size)) == NULL)
{
closegraph();
printf("Error: not enough heap space in save_screen().\n");
printf("SIZE: %d", size);
exit(1);
}
farfree(buf[0]);
getimage(x, y, 50,50, buf[0]);
}
void restore_screen(int x, int y,void far *buf[1])
{
putimage(x,y, buf[0], COPY_PUT);
farfree(buf[0]);
}