SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
aligned_mem.h
Go to the documentation of this file.
1 #ifndef CVD_ALIGNED_MEM_H
2 #define CVD_ALIGNED_MEM_H
3 #include <cassert>
4 
5 namespace CVD {
6  namespace Internal
7  {
8  template <class T, int N=20> struct placement_delete
9  {
10  enum { Size = (1<<N) };
11 
12  struct Array {
13  T data[Size];
14  };
15 
16  static inline void destruct(T* buf)
17  {
18  (*(Array*)buf).~Array();
19  }
20 
21  static inline void free(T* buf, size_t M)
22  {
23  if (M >= Size) {
26  } else {
28  }
29  }
30  };
31 
32  template <class T> struct placement_delete<T,-1>
33  {
34  static inline void free(T*, size_t ) {}
35  };
36 
37  void * aligned_alloc(size_t count, size_t alignment);
38  void aligned_free(void * memory);
39 
40  template <class T>
41  inline T * aligned_alloc(size_t count, size_t alignment){
42  void * data = aligned_alloc(sizeof(T)* count, alignment);
43  return new (data) T[count];
44  }
45 
46  template <class T>
47  inline void aligned_free(T * memory, size_t count){
48  placement_delete<T>::free(memory, count);
49  aligned_free(memory);
50  }
51 
52  } // namespace Internal
53 
54  template <class T, int N> struct AlignedMem {
55  T* mem;
56  size_t count;
57  AlignedMem(size_t c) : count(c) {
58  mem = Internal::aligned_alloc<T>(count, N);
59  }
61  Internal::aligned_free<T>(mem, count);
62  }
63  T* data() { return mem; }
64  const T* data() const { return mem; }
65  };
66 }
67 
68 #endif
void * aligned_alloc(size_t count, size_t alignment)
Definition: aligned_mem.h:41
static void destruct(T *buf)
Definition: aligned_mem.h:16
Definition: abs.h:24
AlignedMem(size_t c)
Definition: aligned_mem.h:57
void aligned_free(void *memory)
static void free(T *, size_t)
Definition: aligned_mem.h:34
const T * data() const
Definition: aligned_mem.h:64
static void free(T *buf, size_t M)
Definition: aligned_mem.h:21