Out of memory after declaration

This is a discussion on Out of memory after declaration within the C Programming forums, part of the General Programming Boards category; Hey all! I just wondered, what if your RAM is almost full and you do not have a pagefile like ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    68

    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,
    Hawk

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    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
    Posts
    68
    I see! Then there is no need to worry about that, thank you for the explanation!
    Hawk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-13-2008, 01:14 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. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM
  5. memory layout and declaration
    By cbastard in forum C Programming
    Replies: 6
    Last Post: 09-13-2005, 12:24 PM

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