home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12502 < prev    next >
Encoding:
Text File  |  1992-08-18  |  2.3 KB  |  58 lines

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