HatchitMath
ht_malloc.h
1 
15 #pragma once
16 
17 #include <iostream>
18 #include <cstdlib>
19 
20 namespace Hatchit {
21 
22  namespace Math {
23 
24  inline void* aligned_malloc(size_t size, size_t alignment)
25  {
26 #ifdef _WIN32
27  return _aligned_malloc(size, alignment);
28 #else
29  void* ptr;
30  int err = posix_memalign(&ptr, alignment, size);
31  if (err == 0)
32  return ptr;
33  else
34  {
35 #ifdef _DEBUG
36  std::cerr << "ALIGNED_MALLOC: Error allocating memory (posix_memalign: " << err << ")" << std::endl;
37 #endif
38  return nullptr;
39  }
40 #endif
41  }
42 
43  inline void aligned_free(void* ptr)
44  {
45 #ifdef _WIN32
46  _aligned_free(ptr);
47 #else
48  free(ptr);
49 #endif
50  }
51  }
52 }
53 
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_intrin.h:33