From cec0afd4a3ac765532a9730bd3ce2978ceb16107 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 18 Oct 2015 03:09:43 +0200 Subject: info: aligments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- doc/info/chap/memory-allocation.texinfo | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'doc/info') diff --git a/doc/info/chap/memory-allocation.texinfo b/doc/info/chap/memory-allocation.texinfo index a368aea..141abaa 100644 --- a/doc/info/chap/memory-allocation.texinfo +++ b/doc/info/chap/memory-allocation.texinfo @@ -659,6 +659,25 @@ It is unspecified how the function works. The implemention in @code{slibc} will allocate a bit of extra memory and shift the returned pointer so that it is aligned. + +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 -- cgit v1.2.3-70-g09d2