Boost logo

Boost :

Subject: Re: [boost] [boost::endian] Summary of discussion #1
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-02 13:25:56

Scott McMurray wrote:
> On 2 June 2010 11:37, Tomas Puverle wrote:
> > Having said that, as the typed interface ultimately relies
> > on copying of data,
> I think the summary here is that the typed approach requires copying
> while using members, and that the untyped approach may require
> swapping before and after use.

Not unreasonable, except the former doesn't imply less swapping than the latter as your phrasing suggests.

> Thinking about that, I believe I've come up with a situation in which
> the typed approach is more efficient than the swapping one. Suppose
> you want to know the width and height of a BMP image on a big-endian
> machine. If you have a way to get around aliasing issues, then
> memory-mapping the beginning of the file, type punning to the typed
> header type, and reading out the 2 values you care about is faster
> than swapping everything in the header. (Yes, you could just swap the
> two fields you care about, for equivalent performance, but that's an
> operation at a different granularity.)

If all I wanted was two values, I wouldn't swap the entire header. I would do exactly what you discounted parenthetically, so the typed approach is not more efficient, it's overkill in your example.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at