Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > the maximum memory size allowed in malloc

Reply
Thread Tools

the maximum memory size allowed in malloc

 
 
Jerry
Guest
Posts: n/a
 
      01-25-2005
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.

 
Reply With Quote
 
 
 
 
Hariprasad Govardhanam
Guest
Posts: n/a
 
      01-25-2005
Hello,
It depends on the platform that the program is working on like
windows, linux or mac. I THINK that the amount of memory is not limited
by anything, but physical memory. Although physical memory is extended
by Virtual memory, malloc allocates contiguous memory (meaning side by
side). So, it depends on the way platform handles the request.
Saying this, I mention that I just think that is the answer. I
hope some great programmers answer your question.

 
Reply With Quote
 
 
 
 
those who know me have no need of my name
Guest
Posts: n/a
 
      01-25-2005
in comp.lang.c i read:

>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.


malloc's argument is a size_t and the range of that type is [0,SIZE_MAX],
so the maximum you can *request* is SIZE_MAX, which value varies from
implementation to implementation and is defined in <limits.h>. whether a
request for SIZE_MAX bytes will succeed depends on factors outside of the
scope of this group.

--
a signature
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-25-2005
"Jerry" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I am wondering what is the maximum size of memory that malloc() could
> handle.


The largest number (in bytes) representable by
standard type 'size_t' (declared by <stdlib.h>
and other headers). This value can and does
vary among implementations. Note that this
value isn't necessarily as large as the host
platform's available memory.

> Is there any limitation on that?


See above.

> Where am I supposed to get
> this kind of information?


How about a C textbook? Or the ISO C standard?

-Mike


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-25-2005

"Hariprasad Govardhanam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hello,
> It depends on the platform that the program is working on like
> windows, linux or mac. I THINK that the amount of memory is not limited
> by anything, but physical memory.


No, it's limited by the range of type 'size_t'.

> Although physical memory is


Might be.

> extended
> by Virtual memory,


Not all platforms feature 'virtual memory'. C has
no concept of virtual memory.

>malloc allocates contiguous memory (meaning side by
> side).


Correct.

>So, it depends on the way platform handles the request.


It depends upon the C implementation.

> Saying this, I mention that I just think that is the answer.


Why not find out rather than guess?

-Mike


 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      01-25-2005
Jerry wrote:
> 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.


It depends on the implementation. It is definitely not greater than
range of type 'size_t' [0, SIZE_MAX] simply because that's the type of
'malloc's parameter.

Also, in a real-life implementation it is quite possible that the actual
range of sizes 'malloc' can handle is smaller than the range if 'size_t'
type. It is possible that an implementation aliases types 'ptrdiff_t'
and 'size_t' to integral types with the same number of bits in value
representation. The former type is signed and the latter is unsigned.
This automatically means that character array size (or, more generally,
object size) in such implementation cannot be greater than SIZE_MAX/2.
This limitation can also be applied to the maximum size 'malloc' can
handle (which is a logical thing to do).

--
Best regards,
Andrey Tarasevich
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-25-2005
those who know me have no need of my name <(E-Mail Removed)> writes:
> in comp.lang.c i read:
>
>>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.

>
> malloc's argument is a size_t and the range of that type is [0,SIZE_MAX],
> so the maximum you can *request* is SIZE_MAX, which value varies from
> implementation to implementation and is defined in <limits.h>. whether a
> request for SIZE_MAX bytes will succeed depends on factors outside of the
> scope of this group.


And a given implementation won't necessarily be able to specify the
maximum size for which malloc() will succeed. Factors that affect
whether malloc() will succeed can be related to the system as a whole
or just to the current program. malloc(1) might succeed in some
circumstances and fail in others.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
italy
Guest
Posts: n/a
 
      01-25-2005
Sorry if my format is a bit odd. I'm using the school's library
computer.

The malloc() function expects an argument of type size_t. The maxium
size is merely the size of size_t(which is implemenation-defined, look
at limits.h). That should answer your question. Also, you shouldn't
allocate a lot of memory at once. Once the memory is freed, it will
become very fragmented, which of course isn't good.

-Adam

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-26-2005
"italy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Sorry if my format is a bit odd. I'm using the school's library
> computer.
>
> The malloc() function expects an argument of type size_t. The maxium
> size is merely the size of size_t(which is implemenation-defined, look
> at limits.h). That should answer your question. Also, you shouldn't
> allocate a lot of memory at once. Once the memory is freed, it will
> become very fragmented, which of course isn't good.


Issues of 'fragmentation' are outside the scope of C,
but what you write above is not typical behavior of
common operating systems. It's typically the use
of many small allocations which cause fragmentation,
not a single large one. IOW I think you've got things
bass ackwards.

-Mike


 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      01-26-2005
Jerry wrote:
>
> 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.


The C90 standard guarantees that you can get at least one object 32
kBytes in size, and this may be static, dynamic, or automatic
memory. C99 guarantees at least 64 kBytes. For any higher limit,
see your system documentation, and the results are off-topic here.

In practice most systems provide considerably more memory.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
malloc and maximum size V.Subramanian, India C Programming 56 02-01-2012 01:27 AM
Re: How to check whether malloc has allocated memory properly in caseif malloc(0) can return valid pointer Gene C Programming 0 12-20-2010 05:33 AM
file upload maximum allowed size error handling J055 ASP .Net 3 07-05-2006 08:27 AM
Malloc/Free - freeing memory allocated by malloc Peter C Programming 34 10-22-2004 10:23 AM
MS Backup Windows 98 "maximum file size allowed by system" PW Computer Support 1 12-05-2003 08:16 AM



Advertisments