Monday, 21 April 2008

Isolated Storage Directories are worth 1Kb

It turns out Isolated Storage folders are worth 1Kb.

This is easy to test, as all you need to do is create a directory in Silverlight, and watch your available isolated storage space, reduce by 1Kb (1024 bytes).

This is all very nice, but in Windows a directory is free (i.e. if you right click on properties of a folder, it takes up zero bytes). The interesting thing, is that if you add a windows folder manually to your isolated storage directory, Silverlight will read your new directory, however it will not take up any space in isolated storage.

This means that the 1Kb of directory space is clearly a Silverlight / Isolated storage thing, not a windows thing. Therefore the AvailableFreeSpace calculation is happening idependently of the underlying file system.

So why would you want to cost a directory at 1Kb, whilst windows costs that very same directory at zero bytes? Well one reason it is that I guess is to stop nasty applications trashing your hard disk with a silverlight application that creates lots of directories (with a default of 100Kb of isolated storage and 1Kb per directory), the nasty application could only create 100 folders.

I have done a screencast on this, which I will upload in the next few days.

5 comments:

Anonymous said...

Wow, you really put a lot of faith into what Explorer tells you, eh? Do you honestly believe that directories are free in "Windows" (I'll assume you meant NTFS)? If so, you should try implementing a filesystem sometime.

chrishayuk said...

I knew somebody would come back to me on my use of the term "free"!

No I don't honestly believe that directories take up no space whatsover. I just didn't particularly want to get into discussions regarding file systems.

The reason I used the term "Windows" rather than "NTFS", is that even with a "FAT32" drive, is that the available free space calculation is independant of the underlying file system size.

Anonymous said...

Ok, fair enough, and bad assumption on my part. I would just suggest that if you make this point again in the future (and I think it's a very valid point), you should avoid mentioning Windows behavior / cost accounting. It isn't necessary, doesn't make sense, and could definitely be misleading to those who don't know any better.

After all, the true cost of a directory is the central point of this discussion, right?

chrishayuk said...

Tom, I agree with a lot of your points, but when I wrote this article last night, I deliberated of how deep i really wanted to make this.

In the end I decided that the point was about Isolated Storage calculating directories at 1Kb (regardless of what is going on at the underlying file system). The reason i wanted to show zero bytes (via windows explorer), is to show that Silverlight is doing its own thing.

In the case of NTFS the Master File Table (MFT) is initially reserved 12.5% of disk space to store metadata regarding directories / files etc. If you create a new directory on the disk (you are just using up the space on the MFT, which has already been preallocated). So although it is not free, it is perceivably free.

More info at: http://support.microsoft.com/kb/174619

I wanted to keep things simple, yes its not technically free, but to all intense purposes it is. It is an important point however, as Silverlight has its own directory cost (only when it creates the directory) which differs from the underlying file system. And that cost is 1Kb.

Tom, you make great points, but I stand by the sentiments of the article. However i think it is valid to flesh out some of these points within the commments area.

Anonymous said...

I guess there could be a number of reasons for this, one might be be because of non-windows OSs, perhaps the best-it-can-do is be consistant across the platforms it supports?