Samer Ibrahim's Blog

The Samer I Warrior on battles with .NET



Which Blogs do I read?

September 2003 - Posts

Going to Oktoberfest...

I'm off to Oktoberfest in Munich, Germany tomorrow night if our friend Isabel will just comply.  I'm quite excited because I really enjoyed my trip to Munich when I was there about a year and some odd months ago.  Now I get to go during what might be the biggest social beer drinking festival in the world.  I can't wait to wet my lips with some good German weissbier.  For those of you who don't know, I'm a home brewer so the entire Oktoberfest thing is of particular interest to me.  I'll drink enough suds for all of you so don't worry if you can't be there.  :)


Arrrays and Streams

During my time off from blogging, I was doing quite a bit of playing around with streams.  Stream this in here, stream this out there.  I noticed two odd things about Streams and arrays in .NET

1.) There is no method in the Stream classes to copy the bytes of one Stream into another Stream, forcing me to do that work myself.  I don't quite understand why this is.  Some Streams have contructors that take another Stream in but not all do.  I can't be the only one who ever has to open one Stream and write it to another and yet not all Streams have a simple way to do this.  It seems like a relatively nature thing to do.  Oh well, it's easy enough to do on your own.

2.) The other thing I noticed is far more peculiar.  While I was moving the bytes of one Stream into another I created a byte buffer to hold the content I was moving.  The code looked like this:

byte[] byteArray = new byte[stream1.Length];

stream1.Read(byteArray, 0, byteArray.Length);

So, what's so odd about this?  Well Stream.Length returns an Int64 and you can create arrays of length Int64 with no problem.  However, the Stream.Read method's signature looks like this: Read(byte[] buffer, Int32 offset, Int32 count ).  Notice however I'm passing the array's length which I initially set to an Int64 to a method that takes an Int32.  The compiler won't complain because Array.Length returns an Int32 which I found odd.  But there is more to this.  In version 1.1 of the framework, Arrays have a LongLength (Brad Wilson pointed this out to me) while this doesn't exist in version 1.0.  Looking at Anakrino I found out that in version 1.0, the code gets decompiled from the DLL as (note I slightly modified what you see below):

stream1.Read(byteArray, 0, check((Int32)byteArray.Length));

I'm not good at reading IL so I didn't look at it and I haven't yet looked at what code generated by 1.0 looks like.

All this is kind of cool and kind of strange IMHO.  I discovered part 2) as I was trying to restore code because I forgot to check a project into Visual Source Safe right before my harddrive died.  I had to restore it from the DLL using Exemplar.  I don't like VSS much but I like losing my code much, much less.

PS  In my last post I said I was going to be posting again soon and really I meant to.  However, as luck would have it, the cable wire outside of my house got yanked and it took them 3 days to get my connection back up.

Posted: Sep 17 2003, 12:17 AM by SamerEyeWarrior | with 3 comment(s)
Filed under: ,
Back to blogging....

After the summer off I think it's time to start blogging again.  Wow have things changed in the Admin pages of these blogs.  Great job Scott.  Anyway, that's all for my first entry... not much content but I need to be reacclimated.

More Posts