1
0

strexpected3 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <stdlib.h>
  2. /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and
  3. By default, Linux follows an optimistic memory allocation strategy.
  4. C89, C99.
  5. Crashes in malloc(), calloc(), realloc(), or free() are almost always
  6. LOC_CHECK_ is set to 0, any detected heap corruption is silently
  7. LOC_CHECK_ value can be useful because otherwise a crash may happen
  8. MMAP_THRESHOLD is 128 kB by default, but is adjustable using mal†NULL or a pointer suitable to be passed to free() is returned. If
  9. NULL, it must have been returned by an earlier call to malloc(), cal†Normally, malloc() allocates memory from the heap, and adjusts the size
  10. OOM killer. For more information, see the description of
  11. RLIMIT_DATA resource limit (see getrlimit(2)).
  12. Recent versions of Linux libc (later than 5.4.23) and glibc (2.x)
  13. The UNIX 98 standard requires malloc(), calloc(), and realloc() to set
  14. The calloc() function allocates memory for an array of nmemb elements
  15. The realloc() function changes the size of the memory block pointed to
  16. The free() function frees the memory space pointed to by ptr, which
  17. The free() function returns no value.
  18. The malloc() and calloc() functions return a pointer to the allocated
  19. The malloc() function allocates size bytes and returns a pointer to the
  20. The realloc() function returns a pointer to the newly allocated memory,
  21. This means that when malloc() returns non-NULL there is no guarantee
  22. This page is part of release 3.35 of the Linux man-pages project. A
  23. allocated memory. The memory is not initialized. If size is 0, then
  24. allocates the memory as a private anonymous mapping using mmap(2).
  25. be found at http://man7.org/linux/man-pages/.
  26. be successfully passed to free().
  27. brk(2), mallopt(3), mmap(2), alloca(3), posix_memalign(3)
  28. by ptr to size bytes. The contents will be unchanged in the range from
  29. call to malloc() with a size of zero, or by a successful call to cal†description of the project, and information about reporting bugs, can
  30. done.
  31. either NULL, or a unique pointer value that can later be successfully
  32. errno to ENOMEM upon failure. Glibc assumes that this is done (and the
  33. errors, such as double calls of free() with the same argument, or over†freeing the same pointer twice.
  34. from ptr, or NULL if the request fails. If size was equal to 0, either
  35. glibc versions of these routines do this); if you use a private malloc
  36. ignored; if set to 1, a diagnostic message is printed on stderr; if set
  37. implementation is used which is designed to be tolerant against simple
  38. implementation that does not set errno, then certain library routines
  39. include a malloc() implementation which is tunable via environment
  40. initialized. If ptr is NULL, then the call is equivalent to mal†is printed on stderr and the program is aborted. Using a nonzero MAL†loc() or realloc(). If the area pointed to was moved, a free(ptr) is
  41. loc() with nmemb or size equal to zero.
  42. loc(size), for all values of size; if size is equal to zero, and ptr is
  43. lopt(3). Allocations performed using mmap(2) are unaffected by the
  44. malloc() returns either NULL, or a unique pointer value that can later
  45. malloc, free, calloc, realloc - Allocate and free dynamic memory
  46. may fail without having a reason in errno.
  47. memory is set to zero. If nmemb or size is 0, then calloc() returns
  48. memory that is suitably aligned for any kind of variable. On error,
  49. much later, and the true cause for the problem is then very hard to
  50. must have been returned by a previous call to malloc(), calloc() or
  51. not NULL, then the call is equivalent to free(ptr). Unless ptr is
  52. of size bytes each and returns a pointer to the allocated memory. The
  53. of the heap as required, using sbrk(2). When allocating blocks of mem†or moved.
  54. ory larger than MMAP_THRESHOLD bytes, the glibc malloc() implementation
  55. passed to free().
  56. protected against, however, and memory leaks can result. If MAL†realloc() fails the original block is left untouched; it is not freed
  57. realloc(). Otherwise, or if free(ptr) has already been called before,
  58. related to heap corruption, such as overflowing an allocated chunk or
  59. runs of a single byte (off-by-one bugs). Not all such errors can be
  60. system is out of memory, one or more processes will be killed by the
  61. that the memory really is available. In case it turns out that the
  62. the kernel source file Documentation/vm/overcommit-accounting.
  63. the new size is larger than the old size, the added memory will not be
  64. the start of the region up to the minimum of the old and new sizes. If
  65. these functions return NULL. NULL may also be returned by a successful
  66. to 2, abort(3) is called immediately; if set to 3, a diagnostic message
  67. track down.
  68. undefined behavior occurs. If ptr is NULL, no operation is performed.
  69. variables. When MALLOC_CHECK_ is set, a special (less efficient)
  70. void *calloc(size_t nmemb, size_t size);
  71. void *malloc(size_t size);
  72. void *realloc(void *ptr, size_t size);
  73. void free(void *ptr);
  74. which is suitably aligned for any kind of variable and may be different
  75. COLOPHON
  76. CONFORMING TO
  77. DESCRIPTION
  78. GNU 2011-09-08 MALLOC(3)
  79. MALLOC(3) Linux Programmer's Manual MALLOC(3)
  80. NAME
  81. NOTES
  82. RETURN VALUE
  83. SEE ALSO
  84. SYNOPSIS