Gromacs  2020.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gmx::anonymous_namespace{alignedallocator.cpp} Namespace Reference


void * alignedMallocGeneric (std::size_t bytes, std::size_t alignment)
 Allocate aligned memory in a fully portable way. More...
void alignedFreeGeneric (void *p)
 Free aligned memory. More...
void * mallocImpl (std::size_t bytes, std::size_t alignment)
 Implement malloc of bytes of memory, aligned to alignment.
void freeImpl (void *p)
 Free aligned memory allocated with mallocImpl().

Function Documentation

void gmx::anonymous_namespace{alignedallocator.cpp}::alignedFreeGeneric ( void *  p)

Free aligned memory.

pMemory pointer previously returned from gmx::internal::alignedFreePortable().

Since this routine relies on the original pointer being stored just before the memory area p points to, bad things will happen if you call this routine with a pointer obtained any other way, or if you call the system free() with a pointer obtained from std::alignedMalloc().

This is an internal routine that should only be called from gmx::alignedFree().
void* gmx::anonymous_namespace{alignedallocator.cpp}::alignedMallocGeneric ( std::size_t  bytes,
std::size_t  alignment 

Allocate aligned memory in a fully portable way.

bytesAmount of memory (bytes) to allocate. The routine will return nullptr if the allocation fails. However, note that asking for zero bytes will return a pointer that is non-null and properly aligned (but obviously you cannot use it, since you promised not to access data beyond the 0 bytes you asked for).
alignmentAlignment specification in bytes, must be a power of 2.
Nonzero pointer if the allocation worked, otherwise nullptr. This routine should only be called from alignedMalloc(), which also does the checking for valid values. This particular function is used for platforms where we have no control of the alignment of memory returned by the system. Instead, we increase the amount of memory requested internally such that we both can create a pointer inside this memory that fulfills the memory alignment requested, and that we have room to store the original pointer just before this area.
This is an internal routine that should only be called from gmx::alignedMalloc(). Just like system-provided routines, it provides memory that is aligned - but not padded.