Wednesday, February 04, 2004

Trivia Answer : Memory allocation management in VB.Net

Can memery allocation (non garbage collected) be done with VB .Net ?

Regular answer : No. C# can do unsafe (non garbage collected) code, and VB.Net cannot

Hideous Answer : Well, yes it is far from being Elegant, but as my good friend and impressively clever RD Clemens once told me in the middle of a discussion on .Net vs. COM : "There can be no purity in software development". So here it is :

    There is full set of Memory management APIs (http://msdn.microsoft.com/library/en-us/memory/base/memory_management_reference.asp) that can be used to do memory alocation (both on the heap and on the stack), copy memory, get a handle to allocated memory, ...etc.

    VB can do PInvoke ...

   PInvoking into Kernel32.dll (or Coredll.dll in Windows Mobile) makes VB capable of dealing with such issues... which is only usefull in very special cases (using other APIs accessible through PInvoke and making sure there is no garbage collection on the arguments passed to the native APIs is the only use I ever needed them for - and only because I had to show VB.Net code (besides C# code) in presentations ...).

   It is not very hard to wrap those calls into some Utility class, and then use it for allocating memory and geting the handles to the objects, which can easily make the code somewhat more elegant ...

   Example (MSDN Article by Derek Mitchell) :

http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfphoneapi.asp

   Have Fun ...

 


.Net | main | Trivia
2/4/2004 1:39:07 PM UTC  #   

  Saturday, January 31, 2004

Trivia Question : unsafe code in VB.Net ?

Can memery allocation (non garbage collected) be done with VB .Net ?

Use the comments to answer ...


.Net | main | Trivia
1/31/2004 3:00:54 PM UTC  #   

  Wednesday, January 28, 2004

Trivia Question Answer

What is the Sphinks looking at (the credits go to my friend Patrick Hynds for thinking of it)

Pizza Hut and KFC ...


main | Travel | Trivia
1/28/2004 9:43:23 PM UTC  #   

  Sunday, January 25, 2004

A trivia question

What is the Sphinks looking at (the credits go to my friend Patrick Hynds for thinking of it)


main | Travel | Trivia
1/25/2004 11:13:03 PM UTC  #