maximum possible allocation

  • Follow


hello

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

thanks

Sami Evangelista
0
Reply evangeli (63) 7/16/2004 3:22:22 PM

Evangelista Sami <evangeli@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  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de
0
Reply Jens.Toerring (807) 7/16/2004 4:10:49 PM


"Evangelista Sami" <evangeli@cnam.fr> wrote in message
news:5f59677c.0407160722.40b0b512@posting.google.com...
> 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


0
Reply mkwahler (3821) 7/16/2004 4:30:34 PM

In 'comp.lang.c', evangeli@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/
0
Reply emdelYOURBRA (457) 7/16/2004 5:29:12 PM

In <Xns9528C63ABCC23hsnoservernet@212.27.42.73> Emmanuel Delahaye <emdelYOURBRA@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: Dan.Pop@ifh.de
0
Reply Dan.Pop (3615) 7/19/2004 3:49:45 PM

In <5f59677c.0407160722.40b0b512@posting.google.com> evangeli@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: Dan.Pop@ifh.de
0
Reply Dan.Pop (3615) 7/19/2004 4:01:57 PM

5 Replies
46 Views

(page loaded in 0.103 seconds)

Similiar Articles:













7/16/2012 8:37:36 PM


Reply: