I was reading this question Deleting a const pointer and wanted to know more about delete behavior. Now, as per my understanding:
delete expression works in two steps:
invoke destructor
then releases the memory (often with a call to free()) by calling operator delete.
operator delete accepts a void*. As part of a test program I over...
After I do, say
Foo* array = new Foo[N];
I've always deleted it this way
delete[] array;
However, sometimes I've seen it this way:
delete[N] array;
As it seems to compile and work (at least in msvc2005), I wonder:
What is the right way to do it?
Why does it compile the other way, then?
...
I am using this sample to decode/encode some data I am retrieving/sending from/to a web server, and I want to use it like this:
BOOL HandleMessage(UINT uMsg,WPARAM wParam,LPARAM lParam,LRESULT* r)
{
if(uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return TRUE;
}
else if(uMsg == WM_CREATE)
{
// Start timer
StartTime...
So I write a short function to remove members from an object that have falsy values:
for (var key in object) {
if (!object[key]) {
delete object[key];
}
}
A couple days later I check source control and someone has changed this to:
var newObject = {};
for (var key in object) {
if (object[key]) { newObject[key] = ob...