Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Use of get_temporary_buffer() : C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-02-2010
Member
 
Join Date: Dec 2009
Posts: 28
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.
Reply With Quote
  #2  
Old 05-02-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
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.
Reply With Quote
  #3  
Old 05-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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
      );
Reply With Quote
  #4  
Old 05-02-2010
Member
 
Join Date: May 2008
Posts: 1,990
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);
}
Reply With Quote
  #5  
Old 05-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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;
}
Output :
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 07:41 AM.