Thursday, May 8, 2008

stl::map equivalent datatype/container/class in VB 6.0

Have you ever searched for the STL::map equivalent in VB6.0? VB doesn’t have any built-in library that supports (key, value) structure/container. If you want one, then you need to create one. I found one such file on web. This is simple Hash table with few examples on how to use.

Check out the link
http://www.devx.com/vb2themax/Tip/19307

Sunday, May 4, 2008

.NET - Notes from C++ Developer


About this post:

I am planning to blog series of articles, about .NET & C# in C++ developer point of view. Below is the first one being published. Hope this article is not a reinventing the wheel effort.

Lets start

About .NET as whole:
Microsoft as like always, copies industries hot selling products into it and sell it on different name. The .NET is not an exception. Microsoft was desperately looking for some technology which can be alternative for SUN's Java. And it messed up lot with its own “COM” technology. In theory, COM provides the best way to implement the component in object oriented way, with out any language, platform, and location dependencies. But the development & maintenance effort of of COM applications are quite high. Hence .NET is born. To say short, .NET is Microsoft alternative for Java , and replacement for COM.So with .NET's introduction, COM is dead and Java faces the competitor.

Intermediate Language (IL):
It is the copy of Java's byte code concept. Microsoft argues that the code written in .NET language and compiled to IL, can run faster than the code written in C++ and compiled to machine code.Since the IL knows the platform the code is going to be executed, it can do the optimization on machine code just before running. But the code compiled to machine code, does not have any idea about what platform it is going to be run. Thus Microsoft argues that .NET language is faster than C++.

Just In Time (JIT):
The .NET code is compiled to IL on compile time. Before execution, the code need to be converted into machine language. But converting the entire IL code into machine code is time consuming. So what .NET does is, compile the code on demand. Microsoft believes that not all the code is going to be executed. So compiling only required code avoids overhead on application start up time.

Compiled NOT interpreted:
Java's byte code is interpreted to machine code on runtime. Hence performance hit. But IL is Compiled to machine code. IL is NOT interpreted at runtime.

One time compiling & Reuse of compiled native code:
On runtime, your IL code is compiled to machine code only once and this machine code is cached till the application exits. So Next time the same part of IL code is executed, it need not to be recompiled.

Language & Platform independence:
COM has this same feature. COM achieves this by standardizing the binary format. Regardless of the language you use, COM framework imposes the standard binary format for the resultant component..NET way of doing this, is thru Common Language Run Time( CLR). Any code written in .NET language is compiled to IL and runs on CLR. This ensures that the code written in any of the .NET supported language is interoperable with the other .NET languages.

Garbage Collection:
.NET runtime manges the memory. So you need not to bother when to free the memory. On application runtime, the garbage collector often examines for any allocated but unused memory and frees them. It is no more the developer's responsibility to release the dynamically allocated memory.

Strong Data typing:
Any variable is strongly typed in .NET, means that you can not have datatype like variant any more in .NET.

Assemblies:
This is modified version of Dlls. The COM dlls hosts the components and registered in Windows registry. But .NET is stated as OS independent ( at least in theory). So .NET libraries cannot depend on Windows registry to store its information about DLL & Component. The .NET Assemblies has embedded meta data that contains information about itself. ( i.e.) The assemblies meta data gives the information about assembly itself. And to avoid version conflicts and name collisions, .NET follows the special directory subtree called Global assembly Cache(GAC).

Application domains:
Developers always start worrying on whether to implement the component in DLL or separate executable. If you keep the components in different process, then communication between those will be complex ( since out of process communication), hence performance degradation. If you keep the component in same process, then there is a risk of, problem in one component could crash the other components as well. .NET introduces the new concept called application domain. Each components runs on its own application domain. All application domains run on single process. One application domain cannot see other application domain's memory. So no worry of one application domain crashing other application domains. Communication between the components are taken care by .NET run time. Since all the components are in the same process, communication between them will be faster.

Summary:
So what did you get best in .NET?
1) No memory leak hassle:
For a C++ developer, memory leaks could be night mare. Though there are lot of tools to find memory leak, finding & fixing the memory leaks could take lot of effort and time. With .NET's Garbage collection, no worry of memory leaks
2) Easier way to achieve what COM can do:
Developers are choosing COM to ensure their components are language interoperable, version controllable and sliced architecture.But all the work falls on developers head hence developing & maintaining applications in COM is time consuming.But .NET does lot of ground work when it comes to implementing components. Hence .NET easy to do but archives the same task.
3) Application domains:
Thru this concept we got both, faster communication between component and safety by securing one components address space from others.
What did you get worst in .NET?
Performance:
Need less to say, since the code is not compiled to native machine code, the run time IL compilation will be considerable performance hit. And garbage collector may examine your application at any point of time. This action is not deterministic. So you cannot have complete control over execution time of your application. But .NET could be faster than Java because of .NET's JIT & compile not interpret concepts.