Boost logo

Boost :

Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: Joshua Boyce (raptorfactor_at_[hidden])
Date: 2012-01-28 09:14:08

On Sat, Jan 28, 2012 at 11:34 PM, Olaf van der Spek <ml_at_[hidden]> wrote:

> On Fri, Jan 27, 2012 at 5:32 PM, Domagoj Saric
> <domagoj.saric_at_[hidden]> wrote:
> > a) the lifetime management bool was changed into a properly typed pointer
> > (this
> > actually takes the same amount of space while it provides a no-op
> AFAIK bool and pointer aren't the same size. How can it still take the
> same amount of space?
> Olaf
> _______________________________________________
> Unsubscribe & other changes:

My guess would be that the compiler promotes the size of a bool to that of
the native word size of the machine because the ease and speed of aligned
memory access outweigh the 'size savings' (as typically your object is
going to need to occupy an entire register, word on the stack, etc --
except when in an array, but that's actually another reason you want to
have the size of the object promoted, as again, unaligned memory access is

Afaik though, in code it will typically still be treated as if it were e.g.
1 byte on x86 (using the AL register instead of EAX), and simply ignoring
the high portion of the register.

Note: Not a compiler/optimization/cpu/etc expert. This is just my amateur
'guess'. If you are really curious, just compile a test and disassemble it
with GDB/WinDbg/IDA/etc, testing the codegen for various scenarios and
optimization flags.

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