Dynamic allocated arrays....
Hi!
Can someone tell me how I can get the size of a dynamic allocated array? I mean how can i find out how many elements have been allocated? For example:
char* pnt = new char[10];
How can i find out how many char elememts have been allocated.
I cant do this:
int size = sizeof(pnt);
because that will only give me the size of the pointer which is 4.
And i cant do this either:
int size = sizeof(*pnt);
because that will give me the size of the type of element pnt points to...Does someone know how i can find out how many elements has been allocated???
Thanks...
Real programmers don't document, if it was hard to write it should be hard to understand
April 20, 2001 12:39 PM
You need to save the array size when allocating it.
eg :
typedef struct {
int size;
char* pChar;
} arrayOfchar;
or use the STL
eg :
typedef struct {
int size;
char* pChar;
} arrayOfchar;
or use the STL
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement