Thursday, December 24, 2009

Cambridge, UK

Last week I went at a conference in Cambridge, UK. While I was there, I was able to see a whole different world and kind of people... and I'm glad I did that! So, here are some picture... :)

On the way to Cambridge...

Peterhouse College

Have fun! :)

Friday, November 13, 2009

My "Self-built grid" published

Hi there...
My article was published in the "Intelligent Distributed Computing III" book. Here's the link to it.

Happy day! :)

Tuesday, November 10, 2009

It's a GO for my PhD Thesis

Hi there...
Last week I received a positive answer regarding my PhD thesis, therefore, I can start researching on my subject "Human-aircraft interaction"... :)

Wednesday, November 4, 2009

Friday, October 23, 2009

How many classes can a single .NET DLL contain?(VS2010 + Parallel)


I just tried the last version of MS VS 2010 beta2 with my little "killer" application(see 2 entries in the past...). The only difference is that I used the Parallel.For method instead of a classic for.
I was happy (really, I was happy! ) that I could find a possible memory leak inside it because the memory used by VS2010 was increasing in a linearly fashion. Therefore, I've decided to post a comment on Connect website to notify MS team to fix this issue.
You can find the entry here.

The best part is that I tried to print screen to get the image of the task manager but it couldn't store it in the clipboard. Pretty cool, right? :D

Happy coding...

Tuesday, October 20, 2009

How many classes a single .NET DLL contain?(Log)

On a Toshiba CoreDuo @2GHz and 2 GB RAM:
@10:30 PM: 0 types.
@2:00 AM: 263.700 types and counting...
@8:52 AM: 419.300 types and counting...
@6:22 PM: 562.400 types and counting (very slow) and the memory is at ~1 GB...

I don't think I'll find out if an assembly can "support" more than 2^24 types inside it... :)

If any of you can create this kind of assembly, please let me know... :)

Happy coding!

Monday, October 19, 2009

How many classes can a single .NET DLL contain?(2)

Hi there... As I said in my early post, I will try to create an application that generates an assembly that has more than 2^24– 1 or 16.777.215 types. So, here's the code:

After 3 hours on a IBM ThinkCentre machine @2GHz with HT and 2GB of RAM, I was able to create only aprox. 200.000 types. I try again on my personal computer and let it run for the whole night... :)

Here's a link to the application.

Have fun... :)

See you with new results late on... :)

Saturday, October 3, 2009

How many classes can a single .NET DLL contain?

Hello all…

There’s a common question in a programming interview that sounds like this:

“How many classes can a single .NET DLL contain?”

I did a little research on the web and I saw that lots of people think that the number is unlimited. Well, in my opinion, this is wrong!

Let me clarify this! Inside MSDN there’s a section on Overview on .NET Framework that contains a section on Metadata and Self-Describing Components. In this section you will find out how metadata is stored inside a Portable Executable and what is the structure of Metadata. When you are looking inside “Metadata and the PE File Structure” , you will find out that each element of your program is stored in a “Metadata table”(one for classes, one for members, a.s.o.). Each element is identified by a “Metadata token” and it’s definition is: ”Each row of each metadata table is uniquely identified in the MSIL portion of the PE file by a metadata token.Metadata tokens are conceptually similar to pointers, persisted in MSIL, that reference a particular metadata table.”(see MSDN). After this section, there is an explanation of these tokens. “A metadata token is a four-byte number. The top byte denotes the metadata table to which a particular token refers (method, type, and so on). The remaining three bytes specify the row in the metadata table that corresponds to the programming element being described.

Let me stop here. If a class is identified in the metadata table using a metadata token and the metadata token is a four-byte number, this means that the number of classes that an assembly can contain is smaller than the biggest number on 3 bytes (the first byte is a connection to the metadata table type). The biggest number on 3 bytes is 2^24– 1 or 16777215.

Therefore, the maximum number of classes (and classes members) that a .NET assembly can contain is 16777215. Am I right? (Wait for comments!)

That’s nice, right? :)

If I’ll have the time, I’ll try to write some code that will generate an assembly with more than 16777215 classes and see if I can use it… :)

Happy coding…

P.S.: Next time when I’ll ask this question on an interview, I’ll be careful on the answer!

Monday, September 21, 2009

Laws of Robotics

Zero Law:
A robot may not harm a human being, unless he finds a way to prove that in the final analysis, the harm done would benefit humanity in general.
First Law:
A robot may not injure a human being or, through inaction, allow a human being to come to harm.
Second Law:
A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.
Third Law:
A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
Forth Law:
A robot must establish its identity as a robot in all cases.
Fifth Law:
A robot must know it is a robot

Thursday, September 17, 2009

Optional keyword in C#

Hi there...

Wouldn't be nice if C# had a optional keyword for the methods/properties in an interface?

interface IMyInterface
optional void OptionalMethod();

void NotOptionalMethod();

public class MyClass1 : IMyInterface
public void NotOptionalMethod()
//implement the method...

public class MyClass2 : IMyInterface
public void NotOptionalMethod()
//implement the method...

public void OptionalMethod()
//implement the method...
I’ve created a thread where you can comment on this.

Wednesday, September 9, 2009

SGAI-2009 Conference


An article of mine on neural networks was accepted to SGAI-2009 conference.

The article will be uploaded soon.

World Wide Web Publishing Error 87

Sometimes ago, I’ve encountered an error when starting the IIS web server. After some looking inside Event viewer, I saw that the World Wide Web Publishing service was unable to start due to the Error 87: The parameter is not correct.

Looking over the Internet, I found all kinds of solutions from resetting the Windows sockets (using netsh winsock reset) to reinstalling the Windows (I hate this last solution! :) ).

But I’ve remembered that I had a problem with the DTC service when invoking a service and I had to modify some registry. The correct registry are:

Windows Registry Editor Version 5.00

"DCOM Protocols"=hex(7):6e,00,63,00,61,00,63,00,6e,00,5f,00,69,00,70,00,5f,00,\





Hope this helps someone/stops him to reinstall Windows! :)

Thursday, August 20, 2009

How safe is Marshal class?


How safe is this piece of code?
//allocate 10 bytes
IntPtr p = Marshal.AllocHGlobal(10);
byte[] a = new byte[20];
for (byte i = 0; i < a.Length; ++i) a[i] = i;
//copy the buffer
Marshal.Copy(a, 0, p, a.Length);

Here's some pictures that shows the memory before and ...
after the copying...

Thursday, August 13, 2009

Project management resource


I just found a website with some Project Management resources. ProjectSmart is the name of the project and you can find it here.

Have fun!

Tuesday, August 11, 2009

Create objects in remote/other AppDomains + unload assemblie(2)

Hi there...

In my previous post I showed how can you unload a assembly within an AppDomain and rebuild the assembly project without stoping the process that loaded the assembly.

In this post I'll show you how can you pass parameters to the newly created AppDomain. For this, you have to create a class that is decorated with Serializable attribute and create some properties that are the actual parameters (it is passed by value. If you want to pass by refrence, you must inherit from MarshalRefByObject - but you will stay in the main AppDomain).
internal class CrossDomainObject
internal string Path { get; set; }
internal string Type { get ; set; }
internal object ObjectSent { get; set; }

internal void DomainCallBack()
//load assembly
Assembly assembly = Assembly.LoadFrom(Path);

//get type
Type type = assembly.GetType(Type);
if (type == null)
throw new NullReferenceException(
string.Format("Unable to get type: {0}", Type));

//create instance in remote domain
object instance= Activator.CreateInstance(type);

if (instance == null)
throw new NullReferenceException("Unable to create object in remote domain");

//get Controller property
PropertyInfo p = commandType.GetProperty("MyProperty");

if (p == null)
throw new NullReferenceException("Unable to get MyProperty property");

if (ObjectSent == null)
throw new NullReferenceException("Convert to ObjectSent failed!");

//Set value to the remote controller
p.SetValue(instance, ObjectSent , null);

The CrossAppDomainDelegate will invoke the DomainCallBack.

CrossDomainObject obj = new CrossDomainObject { ObjectSent = new List<object>(), Path = pathToAssembly, Type = typeOfInstance };
domain.DoCallBack(new CrossAppDomainDelegate(obj.DomainCallBack));

That's about it...

Monday, August 10, 2009

Create objects in remote/other AppDomains + unload assemblies

Hi there...
Today I wanted know how can I unload an assembly. After some Google/Bing/MSDN search, I realized that unloading an assembly is possible only and if only you create a new AppDomain, load the assembly in it and then Unload the AppDomain.

Some articles were about domain.CreateInstanceAndUnwrap(assemblyName, typeName) but the result was always the same: the assembly was loaded in the primary application domain. If you want to rebuild the assembly/project you will find out that it's not possible because the assembly was loaded in the main application domain and you will get and Error 2: file is being used by another process. But there's a trick.

In .NET Framework you can comunicate with others AppDomains using .NET Remoting. The comunication can be done using IPC Remoting (if you have a server and a client) or using the CrossAppDomainDelegate.

This blog entry will conver the case when you want to create a new AppDomain and create some objects in it without stoping the process that has the main application domain.

First of all, you will have to inherit your cross appdomain objects from MarshalByRefObject.
namespace ClassLibrary1
public class Class1 : MarshalByRefObject
public object MyProperty
object a = value;
Console.WriteLine(string.Format("Remote AppDomain ID: {0}", AppDomain.CurrentDomain.Id));

After that, you will have to create a new AppDomain next to your main AppDomain.
static void Main(string[] args)
Console.WriteLine(string.Format("Local AppDomain ID: {0}{1}", AppDomain.CurrentDomain.Id, Environment.NewLine));

while (Console.ReadKey().Key != ConsoleKey.Escape)
Console.WriteLine("Load in other AppDomain... ");
Console.WriteLine("Done... Press ESC to exit!");

private static void LoadInOtherAppDomain()
//create AppDomain
AppDomain domain = AppDomain.CreateDomain("MyTestDomain");
domain.DoCallBack(new CrossAppDomainDelegate(LoadAssembly));

//unload domain
domain = null;

In the LoadAssembly method, you will have to create a new assembly, load the assembly in the newly created AppDomain, find the type of the object that you want to instantiate find methods/properties and call them.

static void LoadAssembly()
Assembly assembly = Assembly.LoadFrom("ClassLibrary1.dll");

Type t = Array.Find(assembly.GetTypes(), ts => ts.FullName == "ClassLibrary1.Class1");

if(t == null)
throw new NullReferenceException("Unable to get type!");

//create instance
object instance = Activator.CreateInstance(t);

if(instance == null)
throw new NullReferenceException("Unable to create an instance!");
//get MyProperty property
PropertyInfo p = instance.GetType().GetProperty("MyProperty");

if (p == null)
throw new NullReferenceException("Unable to get MyProperty property!");

//Set value to the remote property
p.SetValue(instance, new List<object>, null);n

You will see that the result is:
Local AppDomain ID: 1

Load in other AppDomain...
Remote AppDomain ID: 2
Done... Press ESC to exit!
Load in other AppDomain...
Remote AppDomain ID: 3
Done... Press ESC to exit!
Load in other AppDomain...
Remote AppDomain ID: 4
Done... Press ESC to exit!

Well, that's about it...

The nice thing here is that you won't have to stop the process to debug/rebuild the library/assembly that is dynamically loaded! :)

Nice, right?

Happy coding...

Friday, July 17, 2009

Number of threads in Windows (7)

Hi there...
I was always asking myself "how many threads can Windos can create inside one application?". I guess the answer is "depends on hardware".

Today I found a sample application for Managed Stack Explorer that only creates/removes
threads. When I saw it, I immediately remembered my old question and I started to create threads. >:)

After a while - at thread number 440 - the operating system started to work very slow and at 780 I killed the application because my CPU was at 100% for a while now. :)
As a proof, you can see the attached picture.

What's your number? :)

Saturday, July 4, 2009

How to get your data after some partition manager deleted your data

Hi there...

I wanted to install the new Windows 7 RC on my machine side-by-side with my good old Windows XP SP3. I downloaded GParted, Graphical Boot Manager and Windows 7 RC and burned all on some disks. After resizing one partition using GParted and after installing 7, I realized that the data from the resized partition was gone.
After tesing a number(15) of software that should resolve these kind of issues, I found R-Studio. I was able to get my data from my partition in about 1h30! So I recomand R-Studio to anyone who lost some precious data! :)

Happy recovering! :)

I love Windows 7

Hi there..

I've installed the new Windows 7 RC on my laptop and enabled the Aero UI.
It looks so brigth and shiny! I just love it! I can't wait to start developing on it!

If you want to learn more: videos and home page.

Have fun!

Tuesday, June 30, 2009

Hackers' song...

Hi there...

I started reading security books and I just found the Hackers' song...

Put another password in,
Bomb it out and try again,
Try to get past logging in,
We're hacking, hacking, hacking

Try his first wife's maiden name,
This is more than just a game,
It's real fun, but just the same,
It's hacking, hacking, hacking


Friday, June 26, 2009

I'm going to IDC 2009

Hi there...
In my previous post I said that my article - Self built grid - was accepted to IDC 2009 confrence.
The symposium will be held on 13-14 October.

Anyone? :)

Monday, June 1, 2009

My "Self-build grid" article accepted

My article regarding grid computing was accepted at the "3rd International Symposium on Intelligent Distributed Computing - IDC 2009". Of course, I'll have to review it! :)

Happy reading... :)

Thursday, April 30, 2009

Piss against a church

As you can see I've been to Brussels... In Brussels exists a place where you can do  "number 1" near a church legally.. This place is called "Piss against a church" and the church is called Saint Catherine . Here's the picture of this place...

... from Brussels... #18

... from Brussels... #17

... from Brussels... #16

... from Brussels... #15

... from Brussels... #14

... from Brussels... #13

... from Brussels... #12

... from Brussels... #11

... from Brussels... #10