Re: delete POD array - on which platforms does it not work?
Triple-DES wrote:
On 2 Apr, 10:47, Juha Nieminen <nos...@thanks.invalid> wrote:
Martin T. wrote:
Krice wrote:
On 2 huhti, 08:30, "Martin T." <0xCDCDC...@gmx.at> wrote:
delete p; // will work on VC8
free(p); // will also work on VC8
Are you sure these don't mess up anything in VC8?
Yes, 100% sure.
How can you be so sure? Are you sure that they don't, for example,
leak memory? Did you use some kind of profiler to check this or
something?
The _CrtDumpMemoryLeaks() function can be used when running under
the debugger. I too tried this, and was unable to produce a memory
leak on VC8.
How many times did you run the test, and under what conditions?
What if it only fails first Wednesday after a full moon on leap years,
and only if an important customer is watching. That's usually when
Undefined Behavior goes bad.
Without further evidence, I wouldn't go as far as saying that this
is 100% safe on VC8, but it would seem that the most trivial cases
are handled gracefully.
It actually does work, but just by chance. Usually new[] has to store
a count, so the system can later know how many times delete[] has to
call the destructor for the objects in the array. As a space
optimization, the count is not stored for objects without a
destructor, so by pure chance a char[10] object has the same layout as
any other 10 byte memory block.
Do you want to rely on this??
Bo Persson