Thread: maximum allocation using malloc

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    maximum allocation using malloc

    how much memory allocation can we allocate using malloc. what is the maximum value in bytes..

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    As much free virtual memory in a contiguous space that is available.
    In other words, it's operating system dependant and it's also dependant on how much virtual memory you've already used and how fragmented the virtual memory is.
    No hard limit.
    But don't go abusing it because of that.
    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.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Depends on the OS-model, which in turn depends on the processor architecture as well as implementation details in the OS itself [e.g. an OS may well decide to use an arbitrary limit that is lower than what the processor can technically cope with].

    Usual numbers are:
    16-bit DOS - 64KB.
    32-bit Linux - 1 or 3 GB.
    32-bit Windows 2GB.
    64-bit Windows 16TB.
    64-bit Linux 16TB.

    Those are the limits for the virtual address space, of course, if there isn't enough RAM and Swap-space, the limitation of RAM/Swap-space will stop you before the physical memory limit does.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    thank u guys.. thanks a lot

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do remember that malloc will fail is there isn't enough free contiguous virtual memory available.
    Also remember that malloc will fail if the OS says no. The OS might say no if there simply isn't enough available memory, as well as other factors.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dynamic allocation from 1 instead of zero
    By cfdprogrammer in forum C Programming
    Replies: 27
    Last Post: 04-28-2009, 08:21 AM
  2. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 12:26 PM
  3. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 05:37 AM
  4. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM
  5. maximum number
    By drdodirty2002 in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 05:33 PM