Virtual Memory Management In .NET

The hit counter for my blog has just the 10,000 hit milestone today. I had planed to release a comedic themed encryption library for Powershell that shows how some of the functions of GPG can be imitated in Powershell. However, I have not yet finished that library. Instead, I have decided I would release a virtual memory management library I wrote in C#.

One of the projects I’m working on right now required a better understanding of the CPU architectures used today. This inevitably lead me to want to be able to use ASM in C# code. So I decided to start studying NASM and ASM in general, and then found that the .NET heap has execution protection. I then found that I can control the protection bits by calling the virtual memory management functions in the kernel32.dll library. This library is a .NET wrapper for those functions.

The library is documented, but I don’t have any example uses that I can release at this time. While I don’t have any examples to release today I can say that this library is useful for executing either precompiled or dynamically generated native code.

The library is released under the GNU General Public License.
VirtualMemory.7z

On the topic of ASM: I have read a few negative comments in the past about how well the .NET Framework is able to optimize the native code result of an assembly, particularly in the use of SIMD instructions. I feel I should comment on my experience while developing this library. I tested the execution time of two algorithms written in both NASM and C#. The execution time of the first algorithm I tested was ~10 times faster in NASM than what I got from the C# version. On the other hand, the execution time of the second algorithm I tested was only ~10% faster in NASM than in C#, and only after a couple hours of work to optimize the NASM code.
According to my calculations, the speed result of the second algorithm in C# came very close the theoretical limit of my CPUs capacity, close enough that there would be no way to achieve that speed without the use of wide SIMD instructions. This indicates to me that the JITter in .NET Framework is capable of using SIMD instructions properly, while the same JITter may not always understand the algorithm being JITted. This is actually completely inline of my expectations for any compiler.

Advertisements

~ by lunaticexperimentalist on June 23, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: