From Jason Turner

[c.malloc]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpo3sknel5/{from.md → to.md} +33 -23
tmp/tmpo3sknel5/{from.md → to.md} RENAMED
@@ -1,36 +1,46 @@
1
- ### C library <a id="c.malloc">[[c.malloc]]</a>
2
 
3
- Table  [[tab:util.hdr.cstdlib]] describes the header `<cstdlib>`.
 
4
 
5
- The contents are the same as the Standard C library header `<stdlib.h>,`
6
- with the following changes:
 
 
 
 
7
 
8
- The functions `calloc()`, `malloc()`, and `realloc()` do not attempt to
9
- allocate storage by calling `::operator new()` ([[support.dynamic]]).
10
 
11
- The function `free()` does not attempt to deallocate storage by calling
12
- `::operator delete()`.
13
 
14
- ISO C Clause 7.11.2.
 
 
 
15
 
16
- Storage allocated directly with `malloc()`, `calloc()`, or `realloc()`
17
- is implicitly declared reachable (see  [[basic.stc.dynamic.safety]]) on
18
- allocation, ceases to be declared reachable on deallocation, and need
19
- not cease to be declared reachable as the result of an
20
- `undeclare_reachable()` call. This allows existing C libraries to remain
21
- unaffected by restrictions on pointers that are not safely derived, at
22
- the expense of providing far fewer garbage collection and leak detection
23
- options for `malloc()`-allocated objects. It also allows `malloc()` to
24
- be implemented with a separate allocation arena, bypassing the normal
25
  `declare_reachable()` implementation. The above functions should never
26
  intentionally be used as a replacement for `declare_reachable()`, and
27
  newly written code is strongly encouraged to treat memory allocated with
28
- these functions as though it were allocated with `operator new`.
 
29
 
30
- Table  [[tab:util.hdr.cstring]] describes the header `<cstring>`.
 
 
31
 
32
- The contents are the same as the Standard C library header `<string.h>`,
33
- with the change to `memchr()` specified in  [[c.strings]].
34
 
35
- ISO C Clause 7.11.2.
 
 
 
36
 
 
1
+ ### C library memory allocation <a id="c.malloc">[[c.malloc]]</a>
2
 
3
+ [*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
4
+ functions described in this subclause. — *end note*]
5
 
6
+ ``` cpp
7
+ void* aligned_alloc(size_t alignment, size_t size);
8
+ void* calloc(size_t nmemb, size_t size);
9
+ void* malloc(size_t size);
10
+ void* realloc(void* ptr, size_t size);
11
+ ```
12
 
13
+ *Effects:* These functions have the semantics specified in the C
14
+ standard library.
15
 
16
+ *Remarks:* These functions do not attempt to allocate storage by calling
17
+ `::operator new()` ([[support.dynamic]]).
18
 
19
+ Storage allocated directly with these functions is implicitly declared
20
+ reachable (see  [[basic.stc.dynamic.safety]]) on allocation, ceases to
21
+ be declared reachable on deallocation, and need not cease to be declared
22
+ reachable as the result of an `undeclare_reachable()` call.
23
 
24
+ [*Note 1*: This allows existing C libraries to remain unaffected by
25
+ restrictions on pointers that are not safely derived, at the expense of
26
+ providing far fewer garbage collection and leak detection options for
27
+ `malloc()`-allocated objects. It also allows `malloc()` to be
28
+ implemented with a separate allocation arena, bypassing the normal
 
 
 
 
29
  `declare_reachable()` implementation. The above functions should never
30
  intentionally be used as a replacement for `declare_reachable()`, and
31
  newly written code is strongly encouraged to treat memory allocated with
32
+ these functions as though it were allocated with
33
+ `operator new`. — *end note*]
34
 
35
+ ``` cpp
36
+ void free(void* ptr);
37
+ ```
38
 
39
+ *Effects:* This function has the semantics specified in the C standard
40
+ library.
41
 
42
+ *Remarks:* This function does not attempt to deallocate storage by
43
+ calling `::operator delete()`.
44
+
45
+ ISO C 7.22.3.
46