]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libc/stdlib/aligned_alloc.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libc / stdlib / aligned_alloc.3
1 .\" Copyright (C) 2006 Jason Evans <jasone@FreeBSD.org>.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice(s), this list of conditions and the following disclaimer as
9 .\"    the first lines of this file unmodified other than the possible
10 .\"    addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice(s), this list of conditions and the following disclaimer in
13 .\"    the documentation and/or other materials provided with the
14 .\"    distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd January 7, 2011
31 .Dt ALIGNED_ALLOC 3
32 .Os
33 .Sh NAME
34 .Nm aligned_alloc ,
35 .Nm posix_memalign
36 .Nd aligned memory allocation
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In stdlib.h
41 .Ft void *
42 .Fn aligned_alloc "size_t alignment" "size_t size"
43 .Ft int
44 .Fn posix_memalign "void **ptr" "size_t alignment" "size_t size"
45 .Sh DESCRIPTION
46 The
47 .Fn aligned_alloc
48 and
49 .Fn posix_memalign
50 functions allocate
51 .Fa size
52 bytes of memory such that the allocation's base address is an even multiple of
53 .Fa alignment .
54 The
55 .Fn aligned_alloc
56 function returns the allocation, while the
57 .Fn posix_memalign
58 function stores the allocation in the value pointed to by
59 .Fa ptr .
60 .Pp
61 The requested
62 .Fa alignment
63 must be a power of 2 at least as large as
64 .Fn sizeof "void *" .
65 .Pp
66 Memory that is allocated via
67 .Fn aligned_alloc
68 and
69 .Fn posix_memalign
70 can be used as an argument in subsequent calls to
71 .Xr realloc 3 ,
72 .Xr reallocf 3 ,
73 and
74 .Xr free 3 .
75 .Sh RETURN VALUES
76 The
77 .Fn aligned_alloc
78 function returns a pointer to the allocation if successful; otherwise a
79 NULL pointer is returned and
80 .Va errno
81 is set to an error value.
82 .Pp
83 The
84 .Fn posix_memalign
85 function returns the value 0 if successful; otherwise it returns an error value.
86 .Sh ERRORS
87 The
88 .Fn aligned_alloc
89 and
90 .Fn posix_memalign
91 functions will fail if:
92 .Bl -tag -width Er
93 .It Bq Er EINVAL
94 The
95 .Fa alignment
96 parameter is not a power of 2 at least as large as
97 .Fn sizeof "void *" .
98 .It Bq Er ENOMEM
99 Memory allocation error.
100 .El
101 .Sh SEE ALSO
102 .Xr free 3 ,
103 .Xr malloc 3 ,
104 .Xr realloc 3 ,
105 .Xr reallocf 3 ,
106 .Xr valloc 3
107 .Sh STANDARDS
108 The
109 .Fn aligned_alloc
110 function conforms to
111 .St -isoC-2011 .
112 .Pp
113 The
114 .Fn posix_memalign
115 function conforms to
116 .St -p1003.1-2001 .
117 .Sh HISTORY
118 The
119 .Fn posix_memalign
120 function first appeared in
121 .Fx 7.0 .
122 .Pp
123 The
124 .Fn aligned_alloc
125 function first appeared in
126 .Fx 10.0 .