The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Arrrays and Streams

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Samer Ibrahim

Posts: 55
Nickname: ibrahimss
Registered: Aug, 2003

Samer Ibrahim is a .NET programmer... I really don't want a long bio
Arrrays and Streams Posted: Sep 16, 2003 10:48 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Samer Ibrahim.
Original Post: Arrrays and Streams
Feed Title: Samer Ibrahim's Blog
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/SIbrahim/Rss.aspx
Feed Description: The Samer I Warrior on battles with .NET
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Samer Ibrahim
Latest Posts From Samer Ibrahim's Blog

Advertisement

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.

Read: Arrrays and Streams

Topic: Subscriptions with feed:// Previous Topic   Next Topic Topic: Are Web Services Geing Used in Production Today?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use