public
Created

  • Download Gist
aligned_malloc.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/samples/mem_alloc.cpp b/samples/mem_alloc.cpp
index fb04964..4ee16ec 100644
--- a/samples/mem_alloc.cpp
+++ b/samples/mem_alloc.cpp
@@ -17,6 +17,9 @@
#include <stdexcept>
#if defined (_WIN32)
+# undef __MSVCRT_VERSION__
+# define __MSVCRT_VERSION__ 0x0700
+# include <malloc.h>
# include <windows.h>
#else
# include <cstdlib>
@@ -68,6 +71,49 @@ int main(int argc, char* argv[])
buf = NULL;
#if defined(_WIN32)
+ int i = 0;
+ while (i < 3) {
+ t_us.start();
+ buf = static_cast<wchar_t*>(__mingw_aligned_malloc(BUF_SIZE, 0x4000));
+ rv = t_us.stop();
+ if (buf == NULL) throw runtime_error("[ERROR] __mingw_aligned_malloc() failed.");
+ cout << left
+ << setw(32)
+ << "__mingw_aligned_malloc() time: "
+ << rv << endl;
+
+ t_us.start();
+ __mingw_aligned_free(static_cast<void*>(buf));
+ rv = t_us.stop();
+ if (buf == NULL) throw runtime_error("[ERROR] __mingw_aligned_free() failed.");
+ cout << left
+ << setw(32)
+ << "__mingw_aligned_free() time: "
+ << rv << endl;
+ buf = NULL;
+
+ t_us.start();
+ buf = static_cast<wchar_t*>(_aligned_malloc(BUF_SIZE, 0x4000));
+ rv = t_us.stop();
+ if (buf == NULL) throw runtime_error("[ERROR] _aligned_malloc() failed.");
+ cout << left
+ << setw(32)
+ << "_aligned_malloc() time: "
+ << rv << endl;
+
+ t_us.start();
+ _aligned_free(static_cast<void*>(buf));
+ rv = t_us.stop();
+ if (buf == NULL) throw runtime_error("[ERROR] _aligned_free() failed.");
+ cout << left
+ << setw(32)
+ << "_aligned_free() time: "
+ << rv << endl;
+ buf = NULL;
+
+ i++;
+ }
+
// Win32 HeapAlloc()
HANDLE heap = ::HeapCreate(0, 2*BUF_SIZE, 4*BUF_SIZE);
if (heap == NULL) throw runtime_error("[ERROR] HeapCreate() failed.");
C:\devruby\tma\build\samples>mem_alloc.exe
malloc() time:    5.51788
free() time:      1.89935
calloc() time:    14.4366
__mingw_aligned_malloc() time:  8.99002
__mingw_aligned_free() time:    4.96609
_aligned_malloc() time:         8.64092
_aligned_free() time:           4.24539
__mingw_aligned_malloc() time:  6.55764
__mingw_aligned_free() time:    4.49313
_aligned_malloc() time:         6.78286
_aligned_free() time:           4.22287
__mingw_aligned_malloc() time:  6.59518
__mingw_aligned_free() time:    4.06146
_aligned_malloc() time:         6.58392
_aligned_free() time:           4.60199
HeapAlloc() time: 2.79648
HeapFree() time:  1.85055

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.