From 23694b5bb0bc9d7f4ac061e8880b7fd5dc7e308b Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 14 Oct 2014 00:10:38 +0900 Subject: [PATCH] test of MmapAllocator --- test/mprotect_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/mprotect_test.cpp diff --git a/test/mprotect_test.cpp b/test/mprotect_test.cpp new file mode 100644 index 0000000..df8ea84 --- /dev/null +++ b/test/mprotect_test.cpp @@ -0,0 +1,37 @@ +#define XBYAK_NO_OP_NAMES +#include "xbyak/xbyak.h" +#include +#include + +struct Code : Xbyak::CodeGenerator { + Code(int x) + { + mov(eax, x); + ret(); + } +}; + +int main() + try +{ +#ifdef XBYAK_USE_MMAP_ALLOCATOR + puts("use Allocator with mmap"); +#else + puts("use Allocator with posix_memalign"); +#endif + const int N = 70000; + std::vector v(N); + for (int i = 0; i < N; i++) { + v[i] = new Code(i); + } + long long sum = 0; + for (int i = 0; i < N; i++) { + sum += v[i]->getCode()(); + } + for (int i = 0; i < N; i++) { + delete v[i]; + } + printf("sum=%lld\n", sum); +} catch (std::exception& e) { + printf("ERR %s\n", e.what()); +}