Thread: Out Of Memory ????

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    Out Of Memory ????

    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]);
    }
    Last edited by Gugge; 04-06-2002 at 08:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  5. What's the best memory (RAM) type?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 12-15-2001, 12:37 AM