.\" -*-nroff-*- .\" .\" Manual for memory alignment .\" .\" (c) 2009, 2024 Straylight/Edgeware .\" . .\"----- Licensing notice --------------------------------------------------- .\" .\" This file is part of the mLib utilities library. .\" .\" mLib is free software: you can redistribute it and/or modify it under .\" the terms of the GNU Library General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or (at .\" your option) any later version. .\" .\" mLib is distributed in the hope that it will be useful, but WITHOUT .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public .\" License for more details. .\" .\" You should have received a copy of the GNU Library General Public .\" License along with mLib. If not, write to the Free Software .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, .\" USA. . .\"-------------------------------------------------------------------------- .so ../defs.man \" @@@PRE@@@ . .\"-------------------------------------------------------------------------- .TH align 3mLib "4 January 2009" "Straylight/Edgeware" "mLib utilities library" .\" @ALIGN .\" @ALIGNOF . .\"-------------------------------------------------------------------------- .SH NAME align \- alignment utilities . .\"-------------------------------------------------------------------------- .SH SYNOPSIS . .nf .B "#include " .PP .B "union align { ...\& };" .PP .BI "void ALIGN(size_t &" sz ");" .BI "size_t ALIGNOF(" type ); .fi . .\"-------------------------------------------------------------------------- .SH DESCRIPTION . The .B "union align" type is (a reasonable guess at) a type with the implementation's most restrictive alignment requirements; i.e., if a pointer is suitably aligned for .B "union align" value, then it should be suitably aligned for any other value too. .PP The .B ALIGNOF macro returns the alignment required for the given .IR type ; i.e., if an address is suitably aligned for a .I type value if and only if it is a multiple of .BR ALIGNOF( type ) \fR. .PP The .B ALIGN macro rounds its argument .I sz up to the next multiple of .BR "ALIGNOF(union align)" : so, if .I sz is an offset from the start of a suitably aligned chunk of memory, e.g., returned by .BR malloc (3), then .BI ALIGN( sz ) adjusts .I sz in place, including additional padding so that the new offset is also suitably aligned. The intent is to assist with writing fairly portable memory allocators, which must return correctly-aligned memory. . .\"-------------------------------------------------------------------------- .SH "SEE ALSO" . .BR mLib (3). . .\"-------------------------------------------------------------------------- .SH "AUTHOR" . Mark Wooding, . .\"----- That's all, folks --------------------------------------------------