get_temporary_buffer
指定した要素の数を超えていない要素のシーケンスの一時的なストレージを割り当てます。
template<class Type>
pair<Type *, ptrdiff_t>
get_temporary_buffer(
ptrdiff_t _Count
);
パラメーター
- _Count
すべてのメモリに対する必要な要素の最大数割り当てられている必要があるか。
戻り値
最初コンポーネントが割り当てられ、2 番目のコンポーネントがバッファーのサイズを提供する示すメモリへのポインターである pair 格納できる要素の最大数を示します。
解説
関数がメモリ要求を行うには、成功しないことがあります。バッファーが割り当てるには、関数と同じ 2 番目のコンポーネントと null ポインターと等しい最初のコンポーネントとのペアを返します。
この関数は、一時的なメモリにのみ使用する必要があります。
使用例
// memory_get_temp_buf.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
using namespace std;
int main( )
{
// Create an array of ints
int intArray [ ] = { 10, 20, 30, 40, 100, 200, 300, 1000, 2000 };
int count = sizeof ( intArray ) / sizeof ( int );
cout << "The number of integers in the array is: "
<< count << "." << endl;
pair<int *, ptrdiff_t> resultPair;
resultPair = get_temporary_buffer<int>( count );
cout << "The number of elements that the allocated memory\n"
<< "could store is given by: resultPair.second = "
<< resultPair.second << "." << endl;
}
必要条件
ヘッダー : <memory>
名前空間: std