chiark / gitweb /
@@@ fltfmt wip
[mLib] / utils / align.3.in
1 .\" -*-nroff-*-
2 .\"
3 .\" Manual for memory alignment
4 .\"
5 .\" (c) 2009, 2024 Straylight/Edgeware
6 .\"
7 .
8 .\"----- Licensing notice ---------------------------------------------------
9 .\"
10 .\" This file is part of the mLib utilities library.
11 .\"
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.
16 .\"
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.
21 .\"
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,
25 .\" USA.
26 .
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
29 .
30 .\"--------------------------------------------------------------------------
31 .TH align 3mLib "4 January 2009" "Straylight/Edgeware" "mLib utilities library"
32 .\" @ALIGN
33 .\" @ALIGNOF
34 .
35 .\"--------------------------------------------------------------------------
36 .SH NAME
37 align \- alignment utilities
38 .
39 .\"--------------------------------------------------------------------------
40 .SH SYNOPSIS
41 .
42 .nf
43 .B "#include <mLib/align.h>"
44 .PP
45 .B "union align { ...\& };"
46 .PP
47 .BI "void ALIGN(size_t &" sz ");"
48 .BI "size_t ALIGNOF(" type );
49 .fi
50 .
51 .\"--------------------------------------------------------------------------
52 .SH DESCRIPTION
53 .
54 The
55 .B "union align"
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
59 .B "union align"
60 value,
61 then it should be suitably aligned for any other value too.
62 .PP
63 The
64 .B ALIGNOF
65 macro returns the alignment required for the given
66 .IR type ;
67 i.e., if an address is suitably aligned for a
68 .I type
69 value if and only if it is a multiple of
70 .BR ALIGNOF( type ) \fR.
71 .PP
72 The
73 .B ALIGN
74 macro rounds its argument
75 .I sz
76 up to the next multiple of
77 .BR "ALIGNOF(union align)" :
78 so, if
79 .I sz
80 is an offset from the start of a suitably aligned chunk of memory,
81 e.g., returned by
82 .BR malloc (3),
83 then
84 .BI ALIGN( sz )
85 adjusts
86 .I sz
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.
91 .
92 .\"--------------------------------------------------------------------------
93 .SH "SEE ALSO"
94 .
95 .BR mLib (3).
96 .
97 .\"--------------------------------------------------------------------------
98 .SH "AUTHOR"
99 .
100 Mark Wooding, <mdw@distorted.org.uk>
101 .
102 .\"----- That's all, folks --------------------------------------------------