1
+ <!doctype html>
2
+ < html class ="cpprefjp " lang ="ja " itemscope ="" itemtype ="http://schema.org/WebPage ">
3
+ < head >
4
+
5
+
6
+ <!-- Google tag (gtag.js) -->
7
+ < script async src ="https://www.googletagmanager.com/gtag/js?id=G-NXNBNVBTJS "> </ script >
8
+ < script >
9
+ window . dataLayer = window . dataLayer || [ ] ;
10
+ function gtag ( ) { dataLayer . push ( arguments ) ; }
11
+ gtag ( 'js' , new Date ( ) ) ;
12
+
13
+ gtag ( 'config' , 'G-NXNBNVBTJS' ) ;
14
+ </ script >
15
+
16
+
17
+ < meta charset ="UTF-8 ">
18
+
19
+ < title > alloacte_at_least - cpprefjp C++日本語リファレンス</ title >
20
+
21
+ < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
22
+ < meta name ="keywords " content ="
23
+ C++,標準ライブラリ,リファレンス,ドキュメント,STL,std,memory,std,function template,cpp23
24
+ ">
25
+ < meta name ="title " content ="alloacte_at_least - cpprefjp C++日本語リファレンス " />
26
+ < meta itemprop ="name " content ="alloacte_at_least - cpprefjp C++日本語リファレンス " />
27
+ < meta property ="og:title " content ="alloacte_at_least - cpprefjp C++日本語リファレンス " />
28
+ < meta property ="og:url " content ="https://cpprefjp.github.io/reference/memory/allocate_at_least.html " />
29
+ < meta property ="og:site_name " content ="cpprefjp - C++日本語リファレンス " />
30
+ < meta property ="og:type " content ="article " />
31
+ < meta property ="og:description " content ="指定した要素数以上のメモリを確保する。 " />
32
+ < meta name ="twitter:card " content ="summary " />
33
+ < meta name ="twitter:title " content ="alloacte_at_least - cpprefjp C++日本語リファレンス " />
34
+ < meta name ="twitter:url " content ="https://cpprefjp.github.io/reference/memory/allocate_at_least.html " />
35
+ < meta name ="twitter:description " content ="指定した要素数以上のメモリを確保する。 " />
36
+
37
+
38
+ < link rel ="alternate " type ="application/atom+xml " title ="Atom " href ="https://cpprefjp.github.io/rss.xml " />
39
+
40
+
41
+ < link rel ="apple-touch-icon " sizes ="180x180 " href ="../../static/favicons/apple-touch-icon.png?cachebust=0e476399d981581c37613c7023035bba5447c826 ">
42
+ < link rel ="icon " type ="image/png " sizes ="32x32 " href ="../../static/favicons/favicon-32x32.png?cachebust=0e476399d981581c37613c7023035bba5447c826 ">
43
+ < link rel ="icon " type ="image/png " sizes ="16x16 " href ="../../static/favicons/favicon-16x16.png?cachebust=0e476399d981581c37613c7023035bba5447c826 ">
44
+ < link rel ="manifest " href ="../../manifest.json?cachebust=0e476399d981581c37613c7023035bba5447c826 ">
45
+ < meta name ="theme-color " content ="#f5f8fc ">
46
+
47
+ < link rel ="stylesheet " href ="../../static/pygments/default.css?cachebust=0e476399d981581c37613c7023035bba5447c826 ">
48
+ <!-- <link rel="stylesheet" href="../../static/css/root.css"> -->
49
+
50
+
51
+
52
+
53
+
54
+ < link href ="../../static/kunai/css/kunai-stage-0.css?cachebust=0e476399d981581c37613c7023035bba5447c826 " rel ="stylesheet ">
55
+ < link href ="../../static/kunai/css/kunai-stage-1.css?cachebust=0e476399d981581c37613c7023035bba5447c826 " rel ="stylesheet ">
56
+ < link href ="../../static/kunai/css/kunai-stage-2.css?cachebust=0e476399d981581c37613c7023035bba5447c826 " rel ="stylesheet ">
57
+ < link href ="../../static/kunai/css/kunai-stage-3.css?cachebust=0e476399d981581c37613c7023035bba5447c826 " rel ="stylesheet ">
58
+
59
+ < script type ="text/javascript " src ="../../static/kunai/js/kunai-vendor.js?cachebust=0e476399d981581c37613c7023035bba5447c826 "> </ script >
60
+ < script type ="text/javascript " src ="../../static/kunai/js/kunai.js?cachebust=0e476399d981581c37613c7023035bba5447c826 "> </ script >
61
+
62
+ < script type ="text/javascript ">
63
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
64
+ var kn = new Kunai ;
65
+ kn . cpprefjp ( ) ;
66
+ } ) ;
67
+ </ script >
68
+
69
+ </ head >
70
+ < body >
71
+ < header data-kunai-mdinfo ="{"meta": {"header": ["memory"], "namespace": ["std"], "id-type": ["function template"], "cpp": ["cpp23"]}, "sources": [{"id": "78a4ad210c9825fcac351e0cd0e5b4079d322e2f", "source": "#include <iostream>\n#include <memory>\n\nint main() {\n std::allocator<int> alloc;\n\n std::allocation_result<int*> r = std::allocate_at_least(alloc, 3);\n std::cout << \"allocation count:\" << r.count\n << \" bytes:\" << sizeof(int) * r.count\n << std::endl;\n\n alloc.deallocate(r.ptr, r.count);\n}\n"}], "page_id": ["reference", "memory", "allocate_at_least"]} ">
72
+ < nav class ="navbar navbar-default " role ="navigation ">
73
+ < div class ="container-fluid ">
74
+ < div class ="navbar-header ">
75
+ < button type ="button " class ="navbar-toggle collapsed " data-toggle ="collapse " data-target ="#navbar-collapse ">
76
+ < span class ="sr-only "> Toggle navigation</ span >
77
+ < span class ="icon-bar "> </ span >
78
+ < span class ="icon-bar "> </ span >
79
+ < span class ="icon-bar "> </ span >
80
+ </ button >
81
+ < a class ="navbar-brand " href ="../../index.html ">
82
+ < div class ="title-wrapper clearfix ">
83
+ < div class ="title "> cpprefjp - C++日本語リファレンス</ div >
84
+ </ div >
85
+ </ a >
86
+ </ div >
87
+
88
+ < div class ="collapse navbar-collapse " id ="navbar-collapse ">
89
+ < ul class ="nav navbar-nav navbar-right ">
90
+ < li >
91
+ < div class ="google-search ">
92
+
93
+
94
+ < script >
95
+ ( function ( ) {
96
+ var cx = '013316413321391058734:ji_u66hl7hq' ;
97
+ var gcse = document . createElement ( 'script' ) ;
98
+ gcse . type = 'text/javascript' ;
99
+ gcse . async = true ;
100
+ gcse . src = ( document . location . protocol == 'https:' ? 'https:' : 'http:' ) +
101
+ '//www.google.com/cse/cse.js?cx=' + cx ;
102
+ var s = document . getElementsByTagName ( 'script' ) [ 0 ] ;
103
+ s . parentNode . insertBefore ( gcse , s ) ;
104
+ } ) ( ) ;
105
+ </ script >
106
+ < div class ="gcse-search "> </ div >
107
+
108
+
109
+ </ div >
110
+ </ li >
111
+ < li >
112
+ < a href ="https://github.com/cpprefjp/site "> GitHub Project</ a >
113
+ </ li >
114
+ </ ul >
115
+ </ div >
116
+ </ div >
117
+ </ nav >
118
+ </ header >
119
+
120
+ < main id ="main " role ="main ">
121
+ < div class ="container-fluid ">
122
+ < div class ="row ">
123
+ < div class ="col-sm-9 col-sm-push-3 " itemscope itemtype ="http://schema.org/Article ">
124
+ < div class ="row ">
125
+ < div class ="col-sm-12 google-search-result ">
126
+ < gcse:searchresults > </ gcse:searchresults >
127
+ </ div >
128
+ </ div >
129
+ < div class ="row ">
130
+ < div class ="col-sm-12 content-header ">
131
+
132
+ < ol class ="breadcrumb ">
133
+
134
+ < li itemscope itemtype ="http://www.schema.org/SiteNavigationElement ">
135
+ < span >
136
+
137
+ < a href ="../../index.html " itemprop ="url ">
138
+
139
+ < i class ="fa fa-fw fa-home "> </ i >
140
+
141
+ </ a >
142
+
143
+ </ span >
144
+ </ li >
145
+
146
+ < li itemscope itemtype ="http://www.schema.org/SiteNavigationElement ">
147
+ < span >
148
+
149
+ < a href ="../../reference.html " itemprop ="url ">
150
+
151
+ < span itemprop ="name "> リファレンス</ span >
152
+
153
+ </ a >
154
+
155
+ </ span >
156
+ </ li >
157
+
158
+ < li itemscope itemtype ="http://www.schema.org/SiteNavigationElement ">
159
+ < span >
160
+
161
+ < a href ="../../reference/memory.html " itemprop ="url ">
162
+
163
+ < span itemprop ="name "> memory</ span >
164
+
165
+ </ a >
166
+
167
+ </ span >
168
+ </ li >
169
+
170
+ < li class ="active " itemscope itemtype ="http://www.schema.org/SiteNavigationElement ">
171
+ < span >
172
+
173
+
174
+ < span itemprop ="name "> alloacte_at_least</ span >
175
+
176
+
177
+ </ span >
178
+ </ li >
179
+
180
+ </ ol >
181
+ < div class ="crsearch "> </ div >
182
+
183
+ </ div >
184
+ </ div >
185
+ < div class ="row ">
186
+ < div class ="col-sm-12 edit-button ">
187
+
188
+
189
+ < p class ="text-right "> < small >
190
+ 最終更新日時(UTC):
191
+ < span itemprop ="datePublished " content ="2024-08-05T09:00:59 ">
192
+ 2024年08月05日 09時00分59秒
193
+ </ span >
194
+ < br />
195
+ < span itemprop ="author " itemscope itemtype ="http://schema.org/Person ">
196
+ < span itemprop ="name "> Akira Takahashi</ span >
197
+ </ span >
198
+ が更新
199
+ </ small > </ p >
200
+
201
+
202
+ < p class ="text-right ">
203
+ < a class ="history " target ="_blank " href ="https://github.com/cpprefjp/site/commits/master/reference/memory/allocate_at_least.md ">
204
+ < span class ="fa fa-fw fa-clock-o fa-flip-horizontal "> </ span > 履歴
205
+ </ a >
206
+ < a class ="edit " target ="_blank " href ="https://github.com/cpprefjp/site/edit/master/reference/memory/allocate_at_least.md ">
207
+ < span class ="fa fa-fw fa-pencil "> </ span > 編集
208
+ </ a >
209
+ </ p >
210
+ </ div >
211
+ </ div >
212
+ < div class ="row ">
213
+ < div class ="col-sm-12 content-body ">
214
+
215
+ < div class ="identifier-type "> function template</ div > < div class ="header "> <memory></ div > < h1 itemprop ="name "> < span class ="namespace " title ="namespace std "> std::</ span > < span class ="token "> alloacte_at_least</ span > < span class ="cpp cpp23 " title ="C++23で追加 "> (C++23)</ span > </ h1 >
216
+ < div itemprop ="articleBody "> < p > < div class ="codehilite "> < pre > < span > </ span > < code > < span class ="k "> namespace</ span > < span class ="n "> std</ span > < span class ="p "> {</ span >
217
+ < span class ="k "> template</ span > < span class ="o "> <</ span > < span class ="k "> class</ span > < span class ="nc "> Allocator</ span > < span class ="o "> ></ span >
218
+ < span class ="p "> [[</ span > < span class ="n "> nodiscard</ span > < span class ="p "> ]</ span > < span class ="k "> constexpr</ span >
219
+ < span class ="n "> < a href ="allocation_result.html "> allocation_result</ a > </ span > < span class ="o "> <</ span > < span class ="k "> typename</ span > < span class ="n "> < a href ="allocator_traits.html "> allocator_traits</ a > </ span > < span class ="o "> <</ span > < span class ="n "> Allocator</ span > < span class ="o "> >::</ span > < span class ="n "> pointer</ span > < span class ="o "> ></ span >
220
+ < span class ="n "> allocate_at_least</ span > < span class ="p "> (</ span > < span class ="n "> Allocator</ span > < span class ="o "> &</ span > < span class ="n "> a</ span > < span class ="p "> ,</ span > < span class ="kt "> size_t</ span > < span class ="n "> n</ span > < span class ="p "> );</ span > < span class ="c1 "> // (1) C++23</ span >
221
+ < span class ="p "> }</ span >
222
+ </ code > </ pre > </ div >
223
+ </ p >
224
+ < h2 > 概要</ h2 >
225
+ < p > 指定した要素数以上のメモリを確保する。</ p >
226
+ < p > 多くのメモリアロケータはメモリ確保時に指定されたサイズちょうどではなく、少し大きなサイズを確保する。この関数は、確保されたメモリへのポインタに加えて、実際に確保されたメモリサイズを取得できる。</ p >
227
+ < h2 > 戻り値</ h2 >
228
+ < p > 式< code > a.allocate_at_least(n)</ code > が妥当である場合、それを呼び出して返す。そうでなければ、< code > {a.allocate(n), n}</ code > を返す。</ p >
229
+ < h2 > 例</ h2 >
230
+ < p > < div class ="yata " id ="78a4ad210c9825fcac351e0cd0e5b4079d322e2f "> < div class ="codehilite "> < pre > < span > </ span > < code > < span class ="cp "> #include</ span > < span class ="cpf "> < a href ="../iostream.html "> <iostream></ a > </ span > < span class ="cp "> </ span >
231
+ < span class ="cp "> #include</ span > < span class ="cpf "> < a href ="../memory.html "> <memory></ a > </ span > < span class ="cp "> </ span >
232
+
233
+ < span class ="kt "> int</ span > < span class ="nf "> main</ span > < span class ="p "> ()</ span > < span class ="p "> {</ span >
234
+ < span class ="n "> < a href ="allocator.html "> std::allocator</ a > </ span > < span class ="o "> <</ span > < span class ="kt "> int</ span > < span class ="o "> ></ span > < span class ="n "> alloc</ span > < span class ="p "> ;</ span >
235
+
236
+ < span class ="n "> < a href ="allocation_result.html "> std::allocation_result</ a > </ span > < span class ="o "> <</ span > < span class ="kt "> int</ span > < span class ="o "> *></ span > < span class ="n "> r</ span > < span class ="o "> =</ span > < span class ="n "> < span style ="color:#ff0000 "> std::allocate_at_least</ span > </ span > < span class ="p "> (</ span > < span class ="n "> alloc</ span > < span class ="p "> ,</ span > < span class ="mi "> 3</ span > < span class ="p "> );</ span >
237
+ < span class ="n "> < a href ="../iostream/cout.html "> std::cout</ a > </ span > < span class ="o "> <<</ span > < span class ="s "> "allocation count:"</ span > < span class ="o "> <<</ span > < span class ="n "> r</ span > < span class ="p "> .</ span > < span class ="n "> count</ span >
238
+ < span class ="o "> <<</ span > < span class ="s "> " bytes:"</ span > < span class ="o "> <<</ span > < span class ="k "> sizeof</ span > < span class ="p "> (</ span > < span class ="kt "> int</ span > < span class ="p "> )</ span > < span class ="o "> *</ span > < span class ="n "> r</ span > < span class ="p "> .</ span > < span class ="n "> count</ span >
239
+ < span class ="o "> <<</ span > < span class ="n "> < a href ="../ostream/endl.html "> std::endl</ a > </ span > < span class ="p "> ;</ span >
240
+
241
+ < span class ="n "> < a href ="allocator/deallocate.html "> alloc.deallocate</ a > </ span > < span class ="p "> (</ span > < span class ="n "> r</ span > < span class ="p "> .</ span > < span class ="n "> ptr</ span > < span class ="p "> ,</ span > < span class ="n "> r</ span > < span class ="p "> .</ span > < span class ="n "> count</ span > < span class ="p "> );</ span >
242
+ < span class ="p "> }</ span >
243
+ </ code > </ pre > </ div >
244
+ </ div > </ p >
245
+ < h3 > 出力例</ h3 >
246
+ < p > < pre > < code > allocation count:4 bytes:16
247
+ </ code > </ pre > </ p >
248
+ < h2 > バージョン</ h2 >
249
+ < h3 > 言語</ h3 >
250
+ < ul >
251
+ < li > C++23</ li >
252
+ </ ul >
253
+ < h3 > 処理系</ h3 >
254
+ < ul >
255
+ < li > < a href ="../../implementation.html#clang "> Clang</ a > : 19 < span aria-label ="未実装 " role ="img " title ="未実装 "> ❌</ span > </ li >
256
+ < li > < a href ="../../implementation.html#gcc "> GCC</ a > : 14 < span aria-label ="未実装 " role ="img " title ="未実装 "> ❌</ span > </ li >
257
+ < li > < a href ="../../implementation.html#visual_cpp "> Visual C++</ a > : 2022 Update 10 < span aria-label ="未実装 " role ="img " title ="未実装 "> ❌</ span > </ li >
258
+ </ ul >
259
+ < h2 > 関連項目</ h2 >
260
+ < ul >
261
+ < li > < code > < a href ="allocation_result.html "> std::allocation_result</ a > </ code > </ li >
262
+ < li > < code > < a href ="allocator.html "> std::allocator</ a > ::< a href ="allocator/allocate_at_least.html "> allocate_at_least()</ a > </ code > </ li >
263
+ </ ul >
264
+ < h2 > 参照</ h2 >
265
+ < ul >
266
+ < li > < a href ="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0401r6.html " target ="_blank "> P0401R6 Providing size feedback in the Allocator interface</ a > </ li >
267
+ </ ul > </ div >
268
+
269
+ </ div >
270
+ </ div >
271
+ </ div >
272
+
273
+
274
+ < div id ="sidebar " class ="col-sm-3 col-sm-pull-9 ">
275
+ </ div >
276
+
277
+
278
+ </ div >
279
+ </ div >
280
+ </ main >
281
+ < footer class ="footer navbar navbar-default ">
282
+ < div class ="container-fluid ">
283
+ < p > < small >
284
+ 本サイトの情報は、
285
+ < a href ="https://creativecommons.org/licenses/by/3.0/deed.ja " rel ="nofollow "> クリエイティブ・コモンズ 表示 3.0 非移植 ライセンス(CC BY)</ a >
286
+ の下に提供されています。
287
+ </ small > </ p >
288
+ </ div >
289
+ </ footer >
290
+ </ body >
291
+ </ html >
0 commit comments