> -----Original Message----- > From: Discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of > Itay Zandbank > Sent: 30 October 2006 09:53 > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: Re: [ADVANCED-DOTNET] Efficient .NET Networking > > > buffer[50] = (byte) value; > > buffer[51] = (byte) (value >> 8); > > buffer[52] = (byte) (value >> 0x10); > > buffer[53] = (byte) (value >> 0x18); > > Yes, I can do that for integers and longs, but I can't > really do that > for doubles. And of course, the C *(int *)(buffer+offset) = myInt is > faster still. Again, I can write the unsafe code that works > for doubles, > too, but the framework simply seems lacking in that respect. >
Ah, but you only mentioned a 32 bit integer! You may be able to wrap a MemoryStream around your byte[] and then pass it to a BinaryReader or BinaryWriter instance. (BinaryReader/BinaryWriter uses a single 16-byte buffer - big enough to store any standard value type). Then you can use the Write/Read methods (after setting Position on the MemoryStream) without any extra memory allocations. Cheers Simon =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com