This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients neologix, pitrou, rhettinger, tim.peters, vstinner
Date 2013-09-03.09:40:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378201210.34.0.596240804666.issue18835@psf.upfronthosting.co.za>
In-reply-to
Content
Linux provides the following functions:

int posix_memalign(void **memptr, size_t alignment, size_t size);
void *valloc(size_t size);  # obsolete
void *memalign(size_t boundary, size_t size);  # obsolete

Windows provides the following functions:

void* _aligned_malloc(size_t size,  size_t alignment);
void _aligned_free(void *memblock);

_aligned_malloc() has a warning: "Using free is illegal."

Do all platform provide at least a function to allocate aligned memory? Windows, Mac OS X, FreeBSD, old operating systems, etc.? If no, how should we handle these operating systems? Refuse to start Python? Disable some optimizations? How should we check in the source code (ex: setobject.c) than aligned allocations are not supported? An #ifdef?

***

Because of the Windows API, wee need at least two functions:

void* PyMem_MallocAligned(size_t size, size_t alignment);
void PyMem_FreeAligned(void *ptr);

The GIL must be held when callling these functions.


Windows provides also a "realloc" function:

void* _aligned_realloc(void *memblock, size_t size,  size_t alignment);

If the OS does not provide a realloc function, we can reimplement it (malloc, memcpy, free).

void* PyMem_ReallocAligned(void *ptr, size_t size, size_t alignment);

***

For the PEP 445: the new API is different than the PyMemAllocator structure because malloc and realloc functions have an extra "alignment" parameter. We can drop the parameter if the allocator has always the size alignment, but each object may require a different aligment?
History
Date User Action Args
2013-09-03 09:40:10vstinnersetrecipients: + vstinner, tim.peters, rhettinger, pitrou, neologix
2013-09-03 09:40:10vstinnersetmessageid: <1378201210.34.0.596240804666.issue18835@psf.upfronthosting.co.za>
2013-09-03 09:40:10vstinnerlinkissue18835 messages
2013-09-03 09:40:09vstinnercreate