: float *m; : m=new float[4]; : : is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m? : The sizeof( ) operator will return the size in bytes of the array pointed to by m.
: : float *m; : : m=new float[4]; : : : : is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m? : : : The sizeof( ) operator will return the size in bytes of the array pointed to by m. : : size = sizeof(*m);
No, that will tell you the size of the 'float*'. Remember, that 'sizeof' is a compile-time operator - it tells you the size of a type - it has no knowlege of 'new' or 'malloc' or any of that.
: : : float *m; : : : m=new float[4]; : : : : : : is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m? : : : : : The sizeof( ) operator will return the size in bytes of the array pointed to by m. : : : : size = sizeof(*m); : : No, that will tell you the size of the 'float*'. Remember, that 'sizeof' is a compile-time operator - it tells you the size of a type - it has no knowlege of 'new' or 'malloc' or any of that. : : Cheers, : Eric :
I know the sizeof() is not the answer to my problem... So how can i get the size of memory that is allocated to m?
: I know the sizeof() is not the answer to my problem... : So how can i get the size of memory that is allocated to m?
You 'remember' it. Your program obviously knows how much memory it allocated, just keep that number handy. If you're looking for standard function that will tell you how much space is allocated given a particular pointer, there is none.
Comments
: m=new float[4];
:
: is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m?
:
The sizeof( ) operator will return the size in bytes of the array pointed to by m.
size = sizeof(*m);
: : m=new float[4];
: :
: : is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m?
: :
: The sizeof( ) operator will return the size in bytes of the array pointed to by m.
:
: size = sizeof(*m);
No, that will tell you the size of the 'float*'. Remember, that 'sizeof' is a compile-time operator - it tells you the size of a type - it has no knowlege of 'new' or 'malloc' or any of that.
Cheers,
Eric
: : : m=new float[4];
: : :
: : : is there any way that i get the size of memory block allocated to pointer m so that i can find out the size of the array m?
: : :
: : The sizeof( ) operator will return the size in bytes of the array pointed to by m.
: :
: : size = sizeof(*m);
:
: No, that will tell you the size of the 'float*'. Remember, that 'sizeof' is a compile-time operator - it tells you the size of a type - it has no knowlege of 'new' or 'malloc' or any of that.
:
: Cheers,
: Eric
:
I know the sizeof() is not the answer to my problem...
So how can i get the size of memory that is allocated to m?
: So how can i get the size of memory that is allocated to m?
You 'remember' it. Your program obviously knows how much memory it allocated, just keep that number handy. If you're looking for standard function that will tell you how much space is allocated given a particular pointer, there is none.
Cheers,
Eric