get_temporary_buffer
지정된 수의 요소를 초과하지 않는 요소의 시퀀스를 위한 임시 저장소를 할당합니다.
template<class Type>
pair<Type *, ptrdiff_t>
get_temporary_buffer(
ptrdiff_t _Count
);
매개 변수
- _Count
The maximum number of elements requested for which memory is to be allocated.
반환 값
A pair whose first component is a pointer to the memory that was allocated, and whose second component gives the size of the buffer, indicating the largest number of elements that it could store.
설명
The function makes a request for memory and it may not succeed. If no buffer is allocated, then the function returns a pair, with the second component equal to zero and the first component equal to the null pointer.
This function should only be used for memory that is temporary.
예제
// 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