Boost logo

Boost :

Subject: Re: [boost] Proposal: Monotonic Containers
From: Artyom (artyomtnk_at_[hidden])
Date: 2009-06-10 02:53:55


> The space has already been created before the allocator is
> requested to
> provide for new storage.
>
> Otherwise, we could never use a vector<char> on a
> machine that requires
> 16-byte alignment.
>

This is not correct. Allocators allocate memory as single chunk. So, if you
use vector<char> that has size of 10 characters, it would allocate a single
chunk of at least 10 bytes, and it's beginning would be aligned to 8 or 16.

So if you for example, allocate 3 charrecters that start at 0x100 to 0x102,
and then you would try to allocate single integer you need to return
pointer with value 0x104, 0x108 or 0x110-- aligned to 4, 8 or 16
according to architecture requirements, if you would return 0x103 it
may cause illegal operation on some architectures like ARM, hundreds
cycles cost on architectures like IA64 and fault in execution of
atomic operations like in shared_ptr.

You **must** return aligned pointers from allocators.

Artyom

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk