@safe containers with std.experimental.allocator
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 21 16:13:10 PST 2017
On Sat, 21 Jan 2017 22:44:49 +0000, bitwise wrote:
> So I use a custom aligned allocator:
>
> template <class T, int ALIGN>
> class AlignedAllocator {
> T* allocate(size_type n) {
> return (T*)_aligned_malloc(ALIGN, n * sizeof(T));
> }
> };
>
> SIMD operations(aligned load and store) can now safely be used on the
> contents of the std::vector<Vec4>.
This is fine when you have fine-grained control of which allocators are
used for which purpose and you know more about what the code needs than
whoever is consuming the allocator.
alignedAllocate() is for when the code consuming the allocator knows more
about alignment needs than whoever is supplying the allocator, which is
more likely to crop up with coarse-grained allocator control.
More information about the Digitalmars-d
mailing list