InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

SmartMemoryManagement

Posted under .NET Tools | Comments (0)

Description

The .NET Runtime has four different heaps where it stores objects. There are many good articles on how the runtime manages object on these heaps so I won’t into great details about the first three. Here are a two good links to blogs with more information on this topic:

The Large Object Heap

Most of the time, the GC does a well job managing the memory of your programs.
But there are situations, where it performs sub-optimally. One of these situations are so-called Large Objects. All objects with a size greater than 85000 bytes fall within this category. These objects are stored on a separate heap, called Large Object Heap. This heap will neither be defragmented, nor is it collected often, as the GC processes this heap along with the Generation-2 heap.
To reproduce the problem, try to read a large file (say 70MB or so) from a file stream and store it in a MemoryStream. You will see that your memory usage will climb to about 250 MB. Now, destroy your Memorystream and read the file again into another MemoryStream. Now, depending on your memory pressure, the GC will do a Gen-2 Collection (remember.. this is expensive) and reclaim that memory, or you end up with about 500MB of consumed memory.
Now you will probably argue that 250MB are way to much because you could preallocate one large buffer of 70MB for the file via MemoryStream.SetLength(), so you’ll end up with a smaller memory consumption. But there are two things with this argument:
  1. On the second read of the file you memory usage will increase anyway, albeit not to 500 MB but perhaps to about 150MB.
  2. You might not always know in advance how much memory you will need. Think of a server application that reads data over a TCP connection, there might be no hint on how large the amount of received data is. So you end up with increasing your buffer every now and then.

The Solution

The classes you can download below will give you the ability to reuse previously allocated chunks of memory. And once you are done with the memory, you can return it to the pool.
Note that I used weak references within the pool, so the GC can reclaim the buffers within the pool if memory pressure comes up.
Additionally, I have developed a new MemoryStream that uses this object pooling technique.

Downloads


Posted by Henning Krause on Saturday, February 12, 2005 12:26 PM, last modified on Saturday, February 12, 2005 1:25 PM
Permalink | Post RSSRSS comment feed

WebDAVLayer 1.0.1735.12520

Posted under .NET Tools | Comments (2)

More Information

The database that is used by Exchange 2000/2003 is called WebStorageSystem. Each element within this store is accessible via an URL using the WebDAV protocol. This protocol extends the HTTP protocol by exposing several new verbs like PROPFIND, PROPPATCH or SEARCH to name a few. Additionally, the Exchange implementation of the WebDAV protocol has some proprietary commands for batch operations: BMOVE and BCOPY. The parameters of these commands are expressed within the body of the HTTP/WebDAV request as XML.

Features

  • Encapsulation of most of the WebDAV commands.
  • Easy access to folders, elements and properties within the store
  • Support for various authentication schemas: Basic, Digest, NTLM, Kerberos and even the Form-based authentication of Exchange 2003
Unfortunately, there is currently no documentation available. But on the other hand: You can use it free of charge!

Downloads


Posted by Henning Krause on Monday, February 7, 2005 9:04 PM, last modified on Monday, February 7, 2005 9:25 PM
Permalink | Post RSSRSS comment feed

StableEvents

Posted under .NET Tools | Comments (0)

Description

The events within the .NET framework have a severe drawback: If multiple objects have subribed to an event and one subscriber throws an exception, all subsequent subribers are not notified of the event. This is especially true for events used within the remoting framework: If a connection is broken between a event provider and a subscriber, a TargetInvocationException is thrown when the event is invoked.
This class solves this problem by manually invoking each subscriber. All failed notifications are returned to the sender, which in turn can remove the failed subscribers from the list.

Downloads


Technorati:

Posted by Henning Krause on Sunday, January 2, 2005 2:10 PM, last modified on Sunday, January 2, 2005 2:20 PM
Permalink | Post RSSRSS comment feed

MagicPackets

Posted under .NET Tools | Comments (0)

Description

MagicPackets are special IP packets that are recognized by Wake-On-LAN capable network adapters. If such a packet is received by a network adapter, it will boot the computer.
The packet contains the MAC address of the destination computer and is sent either sent to the global broadcast address (255.255.255.255) or the broadcast address of the destination subnet (e.g. 192.168.1.255).

Downloads


Technorati:

Posted by Henning Krause on Sunday, January 2, 2005 1:45 PM, last modified on Sunday, January 2, 2005 1:53 PM
Permalink | Post RSSRSS comment feed

Advanced Thread Pool

Posted under .NET Tools | Comments (0)

Description

The existing threadpool class has several drawbacks:
One example for the latter point is the HttpWebRequest Class, which still goes further and throws an exception when less than two threads are available on the threadpool. (See my article HttpWebRequest fails when several connections are made concurrently).
These drawbacks are evaded with this implementation: Within one process more than one instance can be instantiated and the number of available threads can be adjusted per instances. Additionally, the number of used threads is dynamic, so unused threads will starver over time and will be recreated when load goes up.

Downloads

References

Some of the ideas for this implementation were taken from the CodeProject article Smart Thread Pool by Ami Bar.

Technorati:

Posted by Henning Krause on Sunday, January 2, 2005 12:47 PM, last modified on Sunday, January 2, 2005 1:23 PM
Permalink | Post RSSRSS comment feed