some questions about "new" and "delete"
Posted on 2004-10-17
I have a few questions (I'm a beginner in C++)
1)when you have this code:
typedef struct _STRING
int * buffer;
unsigned long length;
P_STRING p1 = new _STRING;
p1->buffer = new int[p1->length];
how should you delete the pointer ?
(->first the buffer and then the _STRING or only the _STRING)
2)When I know a priori the maximal length, is it faster to use values on the stack in stead of working with new and delete ?
I heard that this is the case, if your stack doesn't becomes to big (but I don't know when that's the case... (and I don't know if this is correct)
3)when you make sth with new, and you want to reuse it later, how should you reinitialise the "allocated memory" (is this term correct?) to 0x00's ??
Thanks in advance.