"Julie" <ju***@nospam.com> wrote in message
news:40**************@nospam.com...
Raja wrote:
How to know the buffer size and increase buffer size in c++.
There is no intrinsic support in C++ to be able to determine the size of
an arbitrary allocated memory block (buffer?). You must keep track of the
memory block yourself.
In a similar vein about determining allocated memory, I recently ran across
this little gem:
//
// A handy two-line array_size() template function
//
#include <cstdlib>
#include <iostream>
using namespace std;
// Uses template type induction to
// discover the size of an array
// so that you don't have to use sizeof(array)/sizeof(element)
template<typename T, int size>
int array_size(T (&)[size]) { return size; };
int main(){
int my_array[] = { 1, 2, 3, 4, 5 };// implicit size
cout << "array size is : " << array_size(my_array) << endl;
system("pause");
}