home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: How many malloc's can I use?
- Message-ID: <1992Aug18.204433.20648@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Aug17.181615.11905@proxxi.se> <9223121.15315@mulga.cs.mu.OZ.AU>
- Date: Tue, 18 Aug 1992 20:44:33 GMT
- Lines: 47
-
- fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
-
- >elias@proxxi.se (Elias M}rtensson (proxxi)) writes:
-
- >>Does ANSI C specify the maximum number of malloc calls that can safely
- >>be made? ...
- >>And does ANSI C specify that largest block of memory that can be
- >>malloc'ed?
-
- >I am fairly sure that the following would be a ANSI-conforming implementation
- >for malloc:
-
- >void *malloc(size_t size) {
- > errno = E_THIS_SYSTEM_DOESNT_HAVE_DYNAMIC_ALLOCATION;
- > return 0;
- >}
-
- >In other words, I fairly ANSI does not make any guarantees as to the amount
- >of memory that can be allocated with malloc. The only constraint is that if
- >for whatever reason it cannot allocate the desired amount, it must return
- >a null pointer after setting errno to an appropriate value.
-
- Almost right. malloc and friends are allowed to set errno but are not
- required to do so.
-
- To answer the original question directly, there is nothing in the
- ANSI/ISO standard as to the number of malloc calls or the size of a
- malloc call which must succeed. As Fergus points out, a system may
- conform to the Standard without being able to allocate heap memory at all.
-
- The main reason for this is that there is very little a Standard could
- say on the subject without making otherwise reasonable implementations
- invalid, or resorting to machine-specific discussions.
-
- Suppose the requirement were that one call of size 1 must succeed. Now
- suppose that you have a program running on a system with quotas on
- memory usage, and the code + static data + stack space just uses up the
- quota. Any request for more memory will fail (including the next
- nested function call). The "quota" mentioned here might be an
- arbitrary decision of the system administrator. It might be the
- amount of memory on the computer. It might be some combination of
- ingredients very hard to characterize, including interactions with
- other processes on the system.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-