Ok, this is a pretty lame question, but I can't find a good answer in my reference book and program is not working in the way I think it should:
What, exactly do the "new" and "delete" functions do? I know I can allocate memory with the "new" function (similar to malloc?), but how does the "delete" function free (similar to "free" function?) up memory?
My question is in regard to a string class I have created. If I say, in the constructor:
char* stringdata = new char[length];
and in the destructor:
delete stringdata;
what exactly is the program doing with the delete function? Is it smart enough to free all of the memory allocated by the call to "new" or is it just freeing up the byte that stringdata is pointing to? Any tip would be greatly appreciated.
What, exactly do the "new" and "delete" functions do? I know I can allocate memory with the "new" function (similar to malloc?), but how does the "delete" function free (similar to "free" function?) up memory?
My question is in regard to a string class I have created. If I say, in the constructor:
char* stringdata = new char[length];
and in the destructor:
delete stringdata;
what exactly is the program doing with the delete function? Is it smart enough to free all of the memory allocated by the call to "new" or is it just freeing up the byte that stringdata is pointing to? Any tip would be greatly appreciated.