|
| |||||||||
| Tags: buffer, cpp, functions, get_temporary_buffer, memory |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Use of get_temporary_buffer() : C++
Hello, I am working in the MNC company as Programmer. I have to complete the project in week. I have the basic knowledge of the functions of C++. But I do not know about the get_temporary_buffer() function. So, I want to gather the information that can be related to the get_temporary_buffer() function. I also want to know about the how get_temporary_buffer() function can works in the C++ language. Therefore, If someone knows anuthing about the get_temporary_buffer() function reply me. |
|
#2
| ||||
| ||||
| Use of get_temporary_buffer() : C++
Hi, The get_temporary_buffer() function can be the template to allocate the sufficient amount of the memory block to store the object. The pair of storage location that can containing the address allocated from it can begins with uninitialized place of storage location, can be return by the get_temporary_buffer() function, If there can be success. The get_temporary_buffer() function can returns the a pair of values zero, if there can be failure. |
|
#3
| ||||
| ||||
| Use of get_temporary_buffer()
The get_temporary_buffer() function can allocates the temporary storage location that can not exceeds a given number of elements, for sequence of elements. The following can be the syntax of the get_temporary_buffer() function as follows : Code: template<class Type>
pair<Type *, ptrdiff_t>
get_temporary_buffer(
ptrdiff_t _Count
); |
|
#4
| |||
| |||
| Program : get_temporary_buffer()
The following example can explains you about the get_temporary_buffer() functionas follows : Code: int main()
{
pair<int*, ptrdf_t> R = get_temporary_buffer(20000, (int*) 0);
int* bf = R.first;
ptrdf_t M = S.second;
uninitialized_fill_n(bf, N, 42);
int* rslt = find_if(bf, bf + N, bind2nd(not_equal_to<int>(), 42));
assert(rslt == bf + N);
return_temporary_buffer(bf);
} |
|
#5
| ||||
| ||||
| Re: Use of get_temporary_buffer() : C++
The program on the get_temporary_buffer() function : Code: #include <memory>
#include <iostream>
using namespace std;
int main( )
{
int itAray [ ] = { 10, 20, 30, 40, 100, 200, 300, 1000, 2000 };
int cnt = sizeof ( itAray ) / sizeof ( int );
cout << "The number of integers in the array is: "
<< count << "." << endl;
pair<int *, ptrdiff_t> rsltPr;
rsltPr = get_temporary_buffer<int>( cnt );
cout << "The number of elements that the allocated memory\n"
<< "could store is given by: resultPair.second = "
<< resultPair.second << "." << endl;
} Code: The number of integers in the array is: 9. The number of elements that the allocated memory could store is given by: resultPair.second = 9. |
![]() |
|
| Thread Tools | Search this Thread |
| |