#endif
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#if GMX_NATIVE_WINDOWS
-#include <windows.h> // only for the page size query purposes
+# include <windows.h> // only for the page size query purposes
#endif
#include "gromacs/utility/gmxassert.h"
* gmx::alignedMalloc(). Just like system-provided routines, it provides
* memory that is aligned - but not padded.
*/
-gmx_unused void *
-alignedMallocGeneric(std::size_t bytes, std::size_t alignment)
+gmx_unused void* alignedMallocGeneric(std::size_t bytes, std::size_t alignment)
{
// The amount of extra memory (beyound what the user asked for) we need is:
// - sizeof(void *), to store the original pointer
// - alignment, to make sure we have an aligned pointer in the area
- void * pMalloc = malloc(bytes + sizeof(void *) + alignment);
+ void* pMalloc = malloc(bytes + sizeof(void*) + alignment);
if (pMalloc == nullptr)
{
// Convert pMalloc to size_t (so we work with raw bytes), add the space we
// need to save the original pointer, and (alignment-1) bytes, and then mask
// out the lowest bits.
- std::size_t mask = ~static_cast<std::size_t>(alignment-1);
- void * pAligned = reinterpret_cast<void *>((reinterpret_cast<std::size_t>(pMalloc) + sizeof(void *) + alignment - 1) & mask);
+ std::size_t mask = ~static_cast<std::size_t>(alignment - 1);
+ void* pAligned = reinterpret_cast<void*>(
+ (reinterpret_cast<std::size_t>(pMalloc) + sizeof(void*) + alignment - 1) & mask);
// Store original pointer. Since we allocated at least sizeof(void *) extra
// space this is always a valid memory location.
- reinterpret_cast<void **>(pAligned)[-1] = pMalloc;
+ reinterpret_cast<void**>(pAligned)[-1] = pMalloc;
return pAligned;
}
* \note This is an internal routine that should only be called from
* gmx::alignedFree().
*/
-gmx_unused void
-alignedFreeGeneric(void *p)
+gmx_unused void alignedFreeGeneric(void* p)
{
if (p)
{
// Pick up the pointer stored just below p, and use that to call free()
- free( reinterpret_cast<void **>(p)[-1] );
+ free(reinterpret_cast<void**>(p)[-1]);
}
}
//! Implement malloc of \c bytes of memory, aligned to \c alignment.
-void *mallocImpl(std::size_t bytes, std::size_t alignment)
+void* mallocImpl(std::size_t bytes, std::size_t alignment)
{
- void * p;
+ void* p;
#if HAVE__MM_MALLOC
- p = _mm_malloc( bytes, alignment );
+ p = _mm_malloc(bytes, alignment);
#elif HAVE_POSIX_MEMALIGN
if (posix_memalign(&p, alignment, bytes) != 0)
{
}
//! Free aligned memory allocated with mallocImpl().
-void freeImpl(void *p)
+void freeImpl(void* p)
{
if (p)
{
}
}
-} // namespace
+} // namespace
// === AlignedAllocationPolicy
return 128;
}
-void *
-AlignedAllocationPolicy::malloc(std::size_t bytes)
+void* AlignedAllocationPolicy::malloc(std::size_t bytes)
{
// Pad memory at the end with another alignment bytes to avoid false sharing
auto size = alignment();
return mallocImpl(bytes, size);
}
-void
-AlignedAllocationPolicy::free(void *p)
+void AlignedAllocationPolicy::free(void* p)
{
freeImpl(p);
}
//! \todo Move this function into sysinfo.cpp where other OS-specific code/includes live
static std::size_t getPageSize()
{
- long pageSize;
+ long pageSize;
#if GMX_NATIVE_WINDOWS
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
pageSize = -1;
#endif
return ((pageSize == -1) ? 4096 // A useful guess
- : static_cast<std::size_t>(pageSize));
+ : static_cast<std::size_t>(pageSize));
}
/* Implements the "construct on first use" idiom to avoid the static
return thePageSize;
}
-void *
-PageAlignedAllocationPolicy::malloc(std::size_t bytes)
+void* PageAlignedAllocationPolicy::malloc(std::size_t bytes)
{
return mallocImpl(bytes, alignment());
}
-void
-PageAlignedAllocationPolicy::free(void *p)
+void PageAlignedAllocationPolicy::free(void* p)
{
freeImpl(p);
}