Monday, January 17, 2011

Dear Oracle Java team

Deal Oracle / Java team,

I am happy you keep popping up Java updates on my computer. All the hard work you put in fixing all this issues and security holes in the Java runtime is appreciated.

I know you have been very busy lately, but have you heard about modern Operating systems like Vista and 7 where you do not have to log on as administrator to apply updates?

If you have heard about them, I am sure you can find time a few moments and make sure Java updater works from non-administrative account using the User Account Control.

The least you can do is to change you fabulous error message that says "Error: Failed to download required installation files", which may be technically right, but does not help a bit, with something more like "Java updates only work when you are logged on as administratior, sorry about the inconvenience" for example.

There are about 1,8 million complains about that when you Google (for you busy folks at Oracle, Google is a web site many people use for searching the web).

Thanks again for your hard work.

Saturday, May 2, 2009

Hold'em Simulator

We just released Burly Marmot Software Hold'em Simulator.

The easy to use program estimates hand odds and provides all sorts of statistics.

Thursday, September 11, 2008

Events versus delegates in C#

Finally somebody clearly defined the difference between C# events and multicast delegates.

We have seen that the event keyword is a modifier for a delegate declaration that allows it to be included in an interface, constraints it invocation from within the class that declares it, provides it with a pair of customizable accessors (add and remove) and forces the signature of the delegate (when used within the .NET framework).

Tuesday, July 1, 2008

"delete []" versus just "delete" in C++

This week I was asked for the second time to "fix" a bug in my code and use "delete []" on arrays instead of "delete". I did an informal survey and all of the people I asked told me using plain "delete" on arrays is wrong.

As I remembered that it is ok, I decided to do some experiments.

I wrote this code and compiled it in VS2008:

#include "stdafx.h"
TCHAR * buf = NULL;
int * intbuf = NULL;

class Foo
int x;
// ~Foo() { x = 2; }
Foo * fooBuf = NULL;

int _tmain(int argc, _TCHAR* argv[])
delete buf;
delete [] buf;
delete intbuf;
delete [] intbuf;
delete fooBuf;
delete [] fooBuf;
return 0;

Now let us check the disassembly:

delete buf;
003E1000 mov eax,dword ptr [buf (3E3370h)]
003E1005 push eax
003E1006 call operator delete (3E105Ch)
delete [] buf;
003E100B mov eax,dword ptr [buf (3E3370h)]
003E1011 push eax
003E1012 call operator delete (3E105Ch)

delete intbuf;
003E1017 mov eax,dword ptr [intbuf (3E3374h)]
003E101D push eax
003E101E call operator delete (3E105Ch)
delete [] intbuf;
003E1023 mov eax,dword ptr [intbuf (3E3374h)]
003E1028 push eax
003E1029 call operator delete (3E105Ch)

delete fooBuf;
003E102E mov eax,dword ptr [fooBuf (3E3378h)]
003E1034 push eax
003E1035 call operator delete (3E105Ch)
delete [] fooBuf;
003E103A mov eax,dword ptr [fooBuf (3E3378h)]
003E1040 push eax
003E1041 call operator delete (3E105Ch)

003E1046 add esp,18h

return 0;

All identical.

Now if you uncomment the destructor interesting things start to happen on the last two deletes:

delete fooBuf;
002C103E mov eax,dword ptr [fooBuf (2C3378h)]
002C1043 add esp,10h
002C1046 test eax,eax
002C1048 je wmain+71h (2C1081h)
002C104A push eax
002C104B mov dword ptr [eax],2
002C1051 call operator delete (2C1094h)
002C1056 mov eax,dword ptr [fooBuf (2C3378h)]
002C105B add esp,4

delete [] fooBuf;
002C105E test eax,eax
002C1060 je wmain+71h (2C1081h)
002C1062 mov ecx,dword ptr [eax-4]
002C1065 push esi
002C1066 lea esi,[eax-4]
002C1069 push offset Foo::~Foo (2C1000h)
002C106E push ecx
002C106F push 4
002C1071 push eax
002C1072 call `eh vector destructor iterator' (2C10F8h)
002C1077 push esi
002C1078 call operator delete (2C1094h)
002C107D add esp,4
002C1080 pop esi

The calls are very different because in second case it goes through the array and destructs individual elements, while in the first just deletes the memory.

“delete” and “delete []” are equivalent unless the array contains objects and that objects have a destructor.

This said it is still probably good idea to use "delete []" for the clarity alone.