Thread: Out of memory after declaration

  1. #1
    Registered User
    Join Date
    Aug 2006

    Out of memory after declaration

    Hey all!

    I just wondered, what if your RAM is almost full and you do not have a pagefile like on windows, and your program declares some variables without the use of allocation functions that exceed the maximum memory? With allocation functions I have some error checking but how do I detect that the system doesn't have enough free memory for my normal declaration needs? What will happen to a C program in that case?

    Thanks in advance,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well if there is insufficient memory to even load the program, the OS will return to the caller of CreateProcess() an error state of insufficient memory.

    If the program runs, but some function declares a lot of local variables, and that blows all the stack allocation, then the OS will kill the program with a similar kind of error message.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    More technically, the stack is allocated once the process starts and is fixed in size - it will neither grow nor shrink, so either it runs or it doesn't.
    Same goes for creating threads - if there isn't enough memory (because it has to allocate a stack), it fails.
    Dynamic memory will fail if there isn't sufficient memory.
    You cannot detect problems if the stack cannot be allocated (unless you are attempting to create a new thread).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Aug 2006
    I see! Then there is no need to worry about that, thank you for the explanation!

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. memory layout and declaration
    By cbastard in forum C Programming
    Replies: 6
    Last Post: 09-13-2005, 12:24 PM