diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-10-18 04:19:10 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-10-18 04:19:10 +0200 |
commit | 3884a2ce457e4073964a1aefcf34c80a5b0df66e (patch) | |
tree | 2ef85af4624c8ee2aadbda3d1a9ba1f4f1f5518c /doc | |
parent | info: realloc (diff) | |
download | slibc-3884a2ce457e4073964a1aefcf34c80a5b0df66e.tar.gz slibc-3884a2ce457e4073964a1aefcf34c80a5b0df66e.tar.bz2 slibc-3884a2ce457e4073964a1aefcf34c80a5b0df66e.tar.xz |
info: malloc aligns pointers
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/info/chap/memory-allocation.texinfo | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/doc/info/chap/memory-allocation.texinfo b/doc/info/chap/memory-allocation.texinfo index 2a9f8dc..cc88dcf 100644 --- a/doc/info/chap/memory-allocation.texinfo +++ b/doc/info/chap/memory-allocation.texinfo @@ -389,6 +389,18 @@ You do not need to write int* ten_integers = (int*)malloc(10 * sizeof(int)); @end example +@tpindex max_align_t +@sc{ISO}@tie{}C11 defines the auxiliary data +type @code{max_align_t} which has a size +the guaranteed to be a power-of-two (possibly +1) multiple of the size of any intrinsic data +type defined by the C standard. Its size a +suitable aligment for any pointer type. +@code{malloc}, even before C11, uses its size +for the aligment of all pointers it returns. +@code{malloc(n)} is hence equivalent to +@code{aligned_alloc(sizeof(max_align_t), n)}. + @item void* calloc(size_t count, size_t size) @fnindex calloc @cpindex Memory allocation without uninitialisation @@ -664,20 +676,6 @@ A recommended practice, to align pointers is: @example p = aligned_alloc(sizeof(*p), n) @end example - -@tpindex max_align_t -@sc{ISO}@tie{}C11 defines the auxiliary data -type @code{max_align_t} which has a size -the guaranteed to be a power-of-two (possibly -1) multiple of the size of any intrinsic data -type defined by the C standard. Its size it -hence suitable for the aligment of any pointer -to such data type. It can thus be a good idea -to try replacing @code{malloc} with the macro -@example -#define malloc(n) \ - aligned_alloc(sizeof(max_align_t), n) -@end example @end table |