Memory shortage in Turbo C

This is a discussion on Memory shortage in Turbo C within the C Programming forums, part of the General Programming Boards category; I'm doing my project in Turbo C++ and it usually runs out of memory. I'm developing an Image Processing System. ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    Unhappy Memory shortage in Turbo C

    I'm doing my project in Turbo C++ and it usually runs out of memory.
    I'm developing an Image Processing System.
    Problem encountered when I try to copy the pixel information of 24 bit BMP file into
    a dynamically allocated 2D array.
    There are no coding bugs since it's working fine on smaller size images(I found that it's working
    for images upto 240*240 size).
    I want to load images upto 900*900.
    How can I do this.
    I tried to switch to different memory models in TC but size of Near Heap and Far heap
    are almost same in all cases( in point of view of Application requirements).
    Please suggest me how can I get rid of this problem.
    Thanking

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    I am afraid that near and far (pointers?) are too archaic for me, but what it does sound like is that you are trying to use too much space on the stack. You may need to allocate space on the heap instead with malloc and friends, (and free the memory when you are done).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have two major sources of memory in TC, the stack, and the heap.

    If you can't get enough memory out of the heap, then try putting your other variables onto the stack, and see how that works.

    Alternatively, put your 2D array onto the stack by making it non-dynamic, and try to free up the rest of the stack, as much as possible.

    Also, you can change your program to allow it to work with just a portion of the whole image, at any one time. Maybe do a quarter of it at a time?

    Bottom line is, TC (and I'm a big TC user still), is not well suited for larger memory demands. Move the program over to MS Visual C Express (it's free), or one of the other 32 bit C compilers.
    That's what I do with my larger programs. I love TC, but ...

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    3
    Quote Originally Posted by Adak View Post
    You have two major sources of memory in TC, the stack, and the heap.

    If you can't get enough memory out of the heap, then try putting your other variables onto the stack, and see how that works.

    Alternatively, put your 2D array onto the stack by making it non-dynamic, and try to free up the rest of the stack, as much as possible.

    Also, you can change your program to allow it to work with just a portion of the whole image, at any one time. Maybe do a quarter of it at a time?

    Bottom line is, TC (and I'm a big TC user still), is not well suited for larger memory demands. Move the program over to MS Visual C Express (it's free), or one of the other 32 bit C compilers.
    That's what I do with my larger programs. I love TC, but ...
    The problem is that I've already written almost 300 lines of code and I doubt if it would work nicely on other compilers like u recommended.
    And I've no prior experience with other C compilers so tell me
    what differences I should expect??

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If your code is standard C, it shouldn't matter what compile you're on. If you've got a bunch of system specific / compiler specific stuff scattered around (gotoxy, etc), then yes, you'll have some trouble.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by gurudeep View Post
    The problem is that I've already written almost 300 lines of code and I doubt if it would work nicely on other compilers like u recommended.
    And I've no prior experience with other C compilers so tell me
    what differences I should expect??
    that's peanuts!

    Standard C code will be fine, just be sure to name the file with a .c extension. Check your options and make sure the C compiler is going to be used for all *.c programs. Otherwise, you'll get the C++ compiler, and that you won't like *that* a bit.

    If you have TC specific stuff, you'll need to use the work-arounds. Like gotoxy() for TC, becomes SetConsoleCursorPosition(), for a console program.

    It takes a while, but download the video from MS also, on how to use the Visual C express IDE. And just be patient. You *WILL* be up to speed with it soon. It just takes some practice.

    Lots of people here use it, so ask away if you have any questions.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    3

    Smile

    Thanks for help.Now I've fair idea and I think It won't be that troublesome switching to
    other compilers.
    One of my friend suggested Dev C++.What are your opinion about it??

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    Dev-C++ is an IDE, not a compiler. The compiler that comes with Dev-C++ (the MinGW port of gcc) is fine, though Dev-C++ itself is rather buggy and has not been updated for years.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    For images that size you are going to have to use the HUGE memory model. I still think you are going to be limited to 64KB elements though. As suggested, switching to a more modern compiler is probably a good idea.
    Last edited by abachler; 11-21-2009 at 02:59 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Fragmentation with Dynamic FIFO Queue
    By fguy817817 in forum Linux Programming
    Replies: 17
    Last Post: 10-31-2009, 04:17 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  4. Program that displays amount of free memory
    By trancedeejay in forum Linux Programming
    Replies: 3
    Last Post: 01-13-2006, 12:27 PM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21