3 .\" Manual for memory alignment
5 .\" (c) 2009, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH align 3mLib "4 January 2009" "Straylight/Edgeware" "mLib utilities library"
35 .\"--------------------------------------------------------------------------
37 align \- alignment utilities
39 .\"--------------------------------------------------------------------------
43 .B "#include <mLib/align.h>"
45 .B "union align { ...\& };"
47 .BI "void ALIGN(size_t &" sz ");"
48 .BI "size_t ALIGNOF(" type );
51 .\"--------------------------------------------------------------------------
56 type is (a reasonable guess at) a type with the
57 implementation's most restrictive alignment requirements;
58 i.e., if a pointer is suitably aligned for
61 then it should be suitably aligned for any other value too.
65 macro returns the alignment required for the given
67 i.e., if an address is suitably aligned for a
69 value if and only if it is a multiple of
70 .BR ALIGNOF( type ) \fR.
74 macro rounds its argument
76 up to the next multiple of
77 .BR "ALIGNOF(union align)" :
80 is an offset from the start of a suitably aligned chunk of memory,
87 in place, including additional padding
88 so that the new offset is also suitably aligned.
89 The intent is to assist with writing fairly portable memory allocators,
90 which must return correctly-aligned memory.
92 .\"--------------------------------------------------------------------------
97 .\"--------------------------------------------------------------------------
100 Mark Wooding, <mdw@distorted.org.uk>
102 .\"----- That's all, folks --------------------------------------------------