Boost logo

Boost :

Subject: Re: [boost] [forward_declare] Interest Inquiry toward Faster Compile Times
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2012-08-02 01:28:12

On Aug 2, 2012, at 1:09 AM, Marc Glisse <marc.glisse_at_[hidden]> wrote:

> On Thu, 2 Aug 2012, Daniel Larimer wrote:
>> I am sure that some types will require proper alignment. Options include always allocating arrays in chunks of 8 bytes by switching to an int64 array and eating the 'overhead'. Anything require alignment greater than 8 bytes?
> Note that int64 could have an alignment of 4 while double would have one of 8, or other strange combinations. Also, vector (as in SSE, not std::vector) elements may want bigger alignment (and malloc has a bug on several platforms that it returns insufficiently aligned memory for those).

Suppose I did this:

template<typename T, unsigned int S, typename A = double>
struct fwd {
        union {
                A _force_align;
                char s[S];
        } _store;

Now users of the API could 'align to' any type they wish, defaulting to double which should be sufficient for most cases. Anyone using forward declarations like this is probably doing so for types that are at least 8 bytes in size and probably not for types leveraging SSE vectors.

Ideally, users of this technique would be opting for compile performance over minimizing memory use. It is bad enough that we have to specify the size manually just to reduce compile times, but specifying the alignment is probably something most users will have no clue on and therefore, the default should assume 'worst case' and align that way.


> --
> Marc Glisse
> _______________________________________________
> Unsubscribe & other changes:

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