Re: How to copy a integer length in a array.
- From: "Peter Duniho" <no.peted.spam@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Jul 2009 13:52:28 -0700
On Mon, 20 Jul 2009 13:22:52 -0700, Ben Voigt [C++ MVP] <rbv@xxxxxxxxxxxxxxxxx> wrote:
[...]The byte twiddling works, of course. But it's lots more verbose and less readable. The array-based version even has to create a small temporary object (the array...of course Arne's version doesn't; his code does essentially what HostToNetworkOrder() does, just without the method call), which depending on how it's done could wind up being less readable _and_ less efficient.
But he wanted the bytes in an array anyway.
Um, sort of. If you look at the code he posted, the only thing he uses the array for is transmitting it. I doubt that he really _needs_ the bytes in an array; he just did the usual "I've already decided how I _think_ this problem should be solved, so I'm stating the solution I think I need, rather than what problem I'm actually trying to solve".
In other words, while he wrote "I want to copy a integer length in a array", what he really needs to do is send a 32-bit integer -- the data length -- in big-endian format prior to sending the bytes that are actually being sent. There's no need at all for that 32-bit integer to be contained in an array in order to accomplish that.
So you'd need HostToNetworkOrder or Arne's version, followed by BitConverter.GetBytes()
Not to produce the same output as the code the OP posted, you wouldn't.
Pete
.
- References:
- How to copy a integer length in a array.
- From: Martin Greul
- Re: How to copy a integer length in a array.
- From: Peter Duniho
- Re: How to copy a integer length in a array.
- From: Martin Greul
- Re: How to copy a integer length in a array.
- From: Ben Voigt [C++ MVP]
- Re: How to copy a integer length in a array.
- From: Peter Duniho
- Re: How to copy a integer length in a array.
- From: Ben Voigt [C++ MVP]
- How to copy a integer length in a array.
- Prev by Date: Re: Efficient visualization of pixmaps
- Next by Date: Re: Efficient visualization of pixmaps
- Previous by thread: Re: How to copy a integer length in a array.
- Next by thread: Re: How to copy a integer length in a array.
- Index(es):
Relevant Pages
|