@@@ mostly bench docs
[mLib] / utils / align.3.in
CommitLineData
c4ccbbf9
MW
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
289651a7 33.\" @ALIGNOF
c4ccbbf9
MW
34.
35.\"--------------------------------------------------------------------------
36.SH NAME
37align \- alignment utilities
38.
39.\"--------------------------------------------------------------------------
40.SH SYNOPSIS
41.
42.nf
43.B "#include <mLib/align.h>"
44.PP
289651a7
MW
45.B "union align { ...\& };"
46.PP
47.BI "void ALIGN(size_t &" sz ");"
48.BI "size_t ALIGNOF(" type );
c4ccbbf9
MW
49.fi
50.
51.\"--------------------------------------------------------------------------
52.SH DESCRIPTION
289651a7
MW
53.
54The
55.B "union align"
56type is (a reasonable guess at) a type with the
57implementation's most restrictive alignment requirements;
58i.e., if a pointer is suitably aligned for
59.B "union align"
60value,
61then it should be suitably aligned for any other value too.
62.PP
63The
64.B ALIGNOF
65macro returns the alignment required for the given
66.IR type ;
67i.e., if an address is suitably aligned for a
68.I type
69value if and only if it is a multiple of
70.BR ALIGNOF( type ) \fR.
71.PP
c4ccbbf9
MW
72The
73.B ALIGN
289651a7
MW
74macro rounds its argument
75.I sz
76up to the next multiple of
77.BR "ALIGNOF(union align)" :
78so, if
79.I sz
80is an offset from the start of a suitably aligned chunk of memory,
81e.g., returned by
82.BR malloc (3),
83then
84.BI ALIGN( sz )
85adjusts
c4ccbbf9 86.I sz
289651a7
MW
87in place, including additional padding
88so that the new offset is also suitably aligned.
89The intent is to assist with writing fairly portable memory allocators,
90which must return correctly-aligned memory.
c4ccbbf9
MW
91.
92.\"--------------------------------------------------------------------------
93.SH "SEE ALSO"
94.
95.BR mLib (3).
96.
97.\"--------------------------------------------------------------------------
98.SH "AUTHOR"
99.
100Mark Wooding, <mdw@distorted.org.uk>
101.
102.\"----- That's all, folks --------------------------------------------------