Re: new and delete operator
Quote:
Originally posted by strange
[list=1][*]why are there two 'delete's and no 'delete[]'?[*]why is an array with size 1 four bytes larger than a plain variable? (with integer this is NOT the case)[/list=1]
Thanks!
Compiler? Version?
I do not get that output when I run on Visual C++ 6.0.
Code:
new: 16
new[]: 20
delete
delete
delete
delete[]
Quote:
why is an array with size 1 four bytes larger than a plain variable? (with integer this is NOT the case)
Because that's how the compiler handles things vis-a-vis the two versions of operator new. Maybe using the array new adds another field to the internal structure used to keep track of allocations, I don't know. In any event, the compiler code generation needs to do it, and the only ones that really know what it's for are the compiler writers.
Quote:
why are there two 'delete's and no 'delete[]'?
The reason for two deletes is that the first delete is for the internal buffer that vector has allocated, and the second delete is for the fact you used operator new to create the vector. Why your version does not have "delete[]" -- maybe your compiler does not support overloading of operator delete[] correctly.
Regards,
Paul McKenzie