LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   malloc() (https://www.linuxquestions.org/questions/programming-9/malloc-221857/)

vijeesh_ep 08-24-2004 02:31 PM

malloc()
 
What is maximum size of block we can allocate with a single malloc() call

jim mcnamara 08-24-2004 02:44 PM

It is implementation and system specific. There isn't one answer for all systems.

Are you getting errors calling malloc? Are you checking errno?
ENOMEM means you have insufficient swap space.

Stack 08-24-2004 03:00 PM

Quote:

Originally posted by jim mcnamara
It is implementation and system specific. There isn't one answer for all systems.

Are you getting errors calling malloc? Are you checking errno?
ENOMEM means you have insufficient swap space.

Well technically the maximum would be the maximum value of size_t.

chrism01 08-25-2004 05:46 AM

Actually, malloc() is defined:
void *malloc(size_t size); - from man malloc

which means this is fine:
http://publications.gbdirect.co.uk/c...d_malloc.html:

#include <stdlib.h> /* declares malloc() */

int *ip, ar[100];
ip = (int *)malloc(sizeof ar);

ie it's N objects, each of size_t, which is still implementation dependent as jim said.

cracauer 08-25-2004 03:50 PM

On a normal x86/32 Linux system the limit for a single malloc is 2 GB. That is because the top 1 GB of the 4 GB virtual address space is taken by the kernel and some idiot placed the shared libraries at 1 GB, fragmenting space.

Note that if you have overcommit memory off, then your available swapspace+RAM is the limit, on some systems (Fedora Core 2 apparently among them) swapspace is the limit.

On many systems, e.g. some BSD systems there is a some-hundred megabyte limit single some mallocs don't fall back to mmap() when brk() fails, and they only brk below the shared libraries also placed at 1 GB. You can get more memory by using anonymous mmap() on your own account.

On a Fedora Core 2 x86/32 system you have a sane placement of shared libraries and you have the 4 GB VM patch applied, so you could map continuously map from 0x0800000 + executable size to the end of 4 GB which would be 3968 MB. However, it seems FC2's kernel does not add RAM + swapspace together, swapspace seems to be the limit. For some additional reason, 2672 MB seems to be the limit in practice on my FC2 machine (no ulimit, 51673032 K swapspace). What the hell?!? My life is ruined, fedora is cutting me off my own swapspace.

EDIT/UPDATE: hm, FC2 places some other anonymous junk at 0x55000000, but not always. That's why you can only map from above that to 4 GB which is 2672 MB.


All times are GMT -5. The time now is 04:46 PM.