473,385 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

maximum possible allocation

hello

is there a maximum size that can be allocated by a malloc call?
is this defined by the standard?

thanks

Sami Evangelista
Nov 14 '05 #1
5 4903
Evangelista Sami <ev******@cnam.fr> wrote:
hello is there a maximum size that can be allocated by a malloc call?
Yes. But that depends on your system, i.e. how much memory you have
and lots of details of your OS (some systems even let you allocate
much more memory than you have real memory, RAM and swap taken to-
gether, but will kill your process if you ever try to use it all).
is this defined by the standard?


No, only restriction is that the size can be stored in a number of
type size_t because of how malloc() is declared.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2

"Evangelista Sami" <ev******@cnam.fr> wrote in message
news:5f**************************@posting.google.c om...
hello

is there a maximum size that can be allocated by a malloc call?
Theoretically, as many bytes whose total number
can be expressed with type 'size_t'. But the
range of 'size_t' is implementation defined.
It must be an unsigned integer type, with a
minimum magnitude of 65535. The maximum single
allocation size possible is also limited by the
host operating system.

is this defined by the standard?


See above.

-Mike
Nov 14 '05 #3
In 'comp.lang.c', ev******@cnam.fr (Evangelista Sami) wrote:
is there a maximum size that can be allocated by a malloc call?
Can't be greater than the value of ((size_t)-1) of your implementation. That
said, non linear objects (arrays of pointers, lists, trees) can be much
bigger [1].
is this defined by the standard?


No. Sky's the limit. The standard only defines minima for the biggest
objetcts (allocated or static).

0x7FFF in C90
0xFFFFU in C99

----------
[1] I wonder what a calloc() is capable of... ((size_t)-1) x ((size_t)-1),
sounds incredible! I guess that even its size might not fit into the biggest
unsigned integer object.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #4
In <Xn***************************@212.27.42.73> Emmanuel Delahaye <em**********@noos.fr> writes:
No. Sky's the limit. The standard only defines minima for the biggest
objetcts (allocated or static).

0x7FFF in C90
0xFFFFU in C99 ^
Is this U supposed to make any difference? What and why?
----------
[1] I wonder what a calloc() is capable of... ((size_t)-1) x ((size_t)-1),
sounds incredible! I guess that even its size might not fit into the biggest
unsigned integer object.


If you use calloc to ask for an object whose size exceeds SIZE_MAX you're
in undefined behaviour territory.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5
In <5f**************************@posting.google.com > ev******@cnam.fr (Evangelista Sami) writes:
is there a maximum size that can be allocated by a malloc call?
is this defined by the standard?


The standard guarantees that at least one object of 32767 bytes can be
allocated, but it doesn't guarantee that it can be *dynamically*
allocated, or even that each and every program can allocate such an
object (think of an implementation with a 16-bit address space where
the text segment already exceeds 32 kB).

An implementation where *all* malloc (and friends) calls fail all the
time is still perfectly conforming. Even malloc(0) is allowed to return
a null pointer, so the answer to your question is not even zero ;-)

OTOH, if you're asking about what is the maximum value that can be
requested from a malloc call (with no guarantees of success), the
answer is (size_t)-1 (or SIZE_MAX in C99).

As a side note, C99 attempts to exclude platforms with a 16-bit
address space from having hosted implementations, as the one
allocatable object size is increased to 65535. For no redeeming
benefits, AFAICS.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Jerry | last post by:
I am wondering what is the maximum size of memory that malloc() could handle. Is there any limitation on that? Where am I supposed to get this kind of information? Thank you everybody.
16
by: alakesh.haloi | last post by:
Hi All Is there a limit on the number of register variables that can be declared and initialized in a C program on a particular hardware platform? If you define more number of register variables...
22
by: Zen | last post by:
Hi, My production machine has 2G of memory, when aspnet_wp.exe goes up to about ~1.2G of memory usage, I start get out-of-memory exception. Other processes don't use as much memory and I added...
3
by: wazurkar | last post by:
hi, I am new to c++. how we can see - how much maximum memory we can allocate through C++ program on Windows XP OS. Though its system dependant I guess it shouldn't be more than 4GB on 32 bit...
5
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
18
by: raylopez99 | last post by:
The maximum int for an array on my machine (a Pentium IV with 2 GB RAM) is < 330 Million...before you get an "out of memory" exception. I simply filled an array of this size with ints...I got as...
7
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The...
4
by: SjaakBanaan | last post by:
Hey all, I have a question that ought to be simple but has given me headaches for a while. I have a table with contact email addresses, say. T ID ContID Priority Emailaddress...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.