Cook Computing

 

« November 2004 »

AddMemoryPressure

Thursday 18 November

Avnrao's Blog has a post GC on small managed resource holding large unmanaged resources... By default small objects will have a low priority as far as GC is concerned but in Whidbey onwards you can boost this by calling GC.AddMemoryPressure. You may want to do this if the small object is holding onto a large unmanaged resource.

Brad Abrams has a post on this with some code:

class Bitmap {

   private long _size;

   Bitmap (string path ) {
      _size = new FileInfo(path).Length;
      GC.AddMemoryPressure(_size);
      // other work
   }

   ~Bitmap() {
      GC.RemoveMemoryPressure(_size);
         // other work
   }
}

And Miguel posted to the Mono-devel list about the problem being addressed:

The problem is that the memory consumption happens in unmanaged world, so the GC has no way of knowing that your very few allocations that you have performed each one has a big impact.

For example, say that the Pixbuf takes 32 bytes of RAM, but the actual data pointed to takes 6 megabytes. If you allocate 256 of these objects, as far as the GC is concerned, you have barely allocated 8k of GC memory, so it is not worth doing a collection for that little memory.

You should use the explicit Dispose method of Pixbuf in these cases (since you are using an unmanaged resource that the managed world has no idea what it is).

Posted by at 08:52 AM. Permalink.

Future Exchange API

Thursday 18 November

I've mentioned XSO (Exchange Server Objects) here a couple of times, wondering what was happening to this managed API for Exchange. Well, according to a post by Tim Anderson, it looks like the future is web services as far as accessing Exchange is concerned. To be expected, I suppose. Tim mentions the prospect of being able to write Java and Compact Framework clients, but he also mentions that Exchange already has WebDAV support and WebDAV can be used cross-platform. The problem with WebDAV is that it is a fairly complex protocol which needs an API (not provided by Microsoft) whereas with a web service I presume you'll be able to load the WSDL into your IDE and generate the code to access the service.

Posted by at 08:07 AM. Permalink.

UTF-8

Saturday 13 November

Via Ned Batchelder I came across the Wikipedia page on UTF-8 which includes a link to Rob Pike's recounting of the invention of this encoding. Well worth reading if you don't know much about UTF-8, given how prevalent it is these days.

Posted by at 04:07 PM. Permalink.

VodaPhone 3G Data Prices

Thursday 11 November

Like Russell Beattie I noticed the launch of Vodaphone's 3G service. I found that the pricing for their 3G/GPRS data card is:

Anticipated usage Price of data card Monthly cost Data included (per month) Additional charge per MB
Low £199 £11.75 5MB £2.35
Medium £149 £23.50 5MB £1.76
High £129 £53.00 450MB £0.88
Power £99 £88.13 1000MB £0.59
This doesn't compare well with Russell's AT&T example of $24.95 per month unlimited date. Prices will drop here eventually but this is "rip-off" Britain and we expect to pay over the odds. We're not doing very well on the broadband front in general. Here 1Mbps is seen as a big deal for domestic customers, which doesn't compare very well with the 30 or 40MBps connections that are available in other parts of the world. Its a pity the billions the government made on the 3G licence infrastructure couldn't have been invested in laying fibre to everyone's homes and offices instead of throwing it away on large numbers of unnecesssary jobs and consultants in the Civil Service, Health Service, and all the other government organisations which have become hugely bloated with a new generation of bureaucrats.

According to the EU's Lisbon accord, there is a goal "to make the EU the most competitive and dynamic knowledge-based economy in the world by 2010". How are we going to achieve that if we don't have the infrastructure in place, and at realistic prices? Why does the EU still pay a huge amount of money in food subsidies to its farmers every year, with the side-effect of serious damage to third world economies and ensuing wide-spread poverty, when we should instead be investing in making this "knowledge-based" economy happen?

Posted by at 07:23 AM. Permalink.

ParseExact

Monday 1 November

Many thanks to Mario Orlandi of Brainstorm who pointed out a bug in the parsing of dateTime.iso8601 values by XML-RPC.NET. The faulty code was:

retVal = DateTime.ParseExact(s, "yyyyMMddTHH:mm:ss", null);
The literals should be surrounded by single quotes:
retVal = DateTime.ParseExact(s, "yyyyMMdd'T'HH':'mm':'ss", null);

Before making the fix I added a new unit test to check dateTime parsing, using the list of locales supported by .NET on the MSDN page for the CultureInfo class. The original code threw an exception for it-IT (Italian - Italy) and fa-FO (Faroese - Faroe Islands) which limited the damage, maybe more so in the latter case, but unfortunately the fixed code still fails for the following locales:

  • ar-SA (Arabic - Saudi Arabia)
  • div-MV (Dhivehi - Maldives)
  • th-TH (Thai - Thailand)

For these locales, no exception is thrown but the DateTime value returned is incorrect. Is the problem in my understanding of format strings or in implementation of ParseExact? I need to do some more research.

By the way, I had a shock when scrolling through the list of locales on the MSDN page mentioned above. I caught sight of eu and for a moment had visions of a EU wide locale which we would all be forced to use at some point by yet another of the endless stream of directives from the EU Commission. Coming shortly after the shameful signing by Tony Blair of the "European Consititution" before holding a referendum on the issue, my anti-EU sensibilities must have been in a rather heightened state of awareness but I need not have worried in this case. It turns out that eu is the code for Basque.

Posted by at 07:42 AM. Permalink.