pbozzoli
10/10/2008 12:23:00 PM
You can't use _countof(), it only works with arrays.
The simplest way I can think of, is to add a variable (size) to your
alloc function:
void alloc(double **ptr, int *size)
{
int i;
*ptr = new double[10];
for(i=0;i<10;++i)
(*ptr)[i]=i*0.36;
*size = sizeof(double)*10;
}
I hope this helps.
Bye
Paolo
On 10 Ott, 12:08, utab <umut.ta...@gmail.com> wrote:
> Dear,
>
> Is there a way to get the allocated size of the val in the code below?
> Actual problem is that I have a double pointer in code and its addressed
> is passed to a routine which does some allocation for this pointer to
> pointer if I am right in the description. I tried to reproduce a very
> simple code for this. Is that possible to get the allocated size in bytes
> in main or it should be done in the function itself, but in main I should
> be able to perform some operations on this vector? This is actually a C
> code I am trying to interface in C++.
>
> #include<iostream>
>
> using namespace std;
>
> void alloc(double **ptr)
> {
> int i;
> *ptr = new double[10];
> for(i=0;i<10;++i)
> (*ptr)[i]=i*0.36;
>
> }
>
> int main()
> {
> double* val;
> alloc(&val);
> // how to get the allocated size or is that
> // possible to retrieve some elements for the
> // above allocation ?
> return 0;
>
> }
>
>