LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-24-2004, 02:31 PM   #1
vijeesh_ep
Member
 
Registered: Jul 2004
Location: India
Distribution: Redhat-8
Posts: 35

Rep: Reputation: 15
Question malloc()


What is maximum size of block we can allocate with a single malloc() call
 
Old 08-24-2004, 02:44 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
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.
 
Old 08-24-2004, 03:00 PM   #3
Stack
Member
 
Registered: Oct 2003
Distribution: FreeBSD
Posts: 325

Rep: Reputation: 30
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.
 
Old 08-25-2004, 05:46 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,267

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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.
 
Old 08-25-2004, 03:50 PM   #5
cracauer
Member
 
Registered: Jul 2004
Location: Boston, MA, USA
Distribution: FreeBSD, Debian/AMD64, Ubuntu/i386
Posts: 59

Rep: Reputation: 15
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.

Last edited by cracauer; 08-25-2004 at 03:53 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
malloc eagle683 Programming 6 05-22-2005 02:40 PM
problem using malloc in C huble Programming 10 03-27-2005 12:45 AM
malloc in c programming saiz66 Programming 18 10-04-2004 02:00 PM
malloc debugger legolas_t Programming 3 07-04-2004 01:32 PM
about malloc eshwar_ind Programming 11 02-18-2004 03:41 PM


All times are GMT -5. The time now is 09:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration