- Why the
posix_memalign
is written as::posix_memalign
? - What is
memory
here?
I am looking to benchmark the read and write speeds of my cache memories and RAM. For this purpose, I want to use google benchmark library and I saw an example code that utilizes it. More or less I get the idea of the code but what does memory
stand here? And why are we making it as a pointer to void? Also, why the example writes posix_memalign
with ::
? Is it because we are referencing to the google benchmark class?
#include <cstddef>
#include <cstdlib>
#include <string.h>
#include <emmintrin.h>
#include <immintrin.h>
#include "benchmark/benchmark.h"
#define ARGS \
->RangeMultiplier(2)->Range(1024, 2*1024*1024) \
->UseRealTime()
template <class Word>
void BM_write_seq(benchmark::State& state) {
void* memory;
if (::posix_memalign(&memory, 64, state.range_x()) != 0) return;
void* const end = static_cast<char*>(memory) + state.range_x();
Word* const p0 = static_cast<Word*>(memory);
Word* const p1 = static_cast<Word*>(end);
Word fill; ::memset(&fill, 0xab, sizeof(fill));
while (state.KeepRunning()) {
for (Word* p = p0; p < p1; ++p) {
benchmark::DoNotOptimize(*p = fill);
}
}
::free(memory);
}