On 01/21/2017 12:14 PM, bitwise wrote:
On Saturday, 21 January 2017 at 16:28:16 UTC, Andrei Alexandrescu wrote:
alignedAllocate provides access to OS/clib-provided primitives for
aligned allocation. Those don't require a special deallocation
function, see e.g.
http://en.cppreference.com/w/c/memory/aligned_alloc. -- Andrei

This makes sense, but then shouldn't alignedAllocate() be a free
function that could be used to make an aligned allocator?

You mean an aligned allocation? But then the actual method, and whether it is supported at all or not, depends on the allocator.

Again, the point of an allocator is to provide a standard interface for
memory allocation. The user of which shouldn't have to know how that
memory was allocated, and I can't think of a case where this would be
desired either.

I don't understand this. It's possible there's a confusion at a different level, and we're discussing the consequences.

To reboot:

* Some applications need memory aligned at special powers of two, most are okay with more generic alignments such as word-level. See the "alignment" enum that each allocator must define.

* Some allocators do offer allocations at unusual powers of two by means of alignedAllocate. Don't call it naively! Only applications that need such things (e.g. page-aligned, cache-line-aligned, etc) should need those.

* Those allocators must be able to deallocate memory allocated with allocate() or alignedAllocate() with a single primitive deallocate().


Andrei

Reply via email to