OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
memory_array.hpp
1 /*
2  * memory_stride.hpp
3  *
4  * Created on: Aug 17, 2014
5  * Author: Pietro Incardona
6  */
7 
8 #ifndef MEMORY_ARRAY_HPP_
9 #define MEMORY_ARRAY_HPP_
10 
11 #include "memory/memory.hpp"
12 #include "Memleak_check.hpp"
13 
24 template<typename T>
26 {
27 
28 #if defined(__GNUG__) || defined(__clang__)
29 
31  T __attribute__((aligned(16))) * ptr;
32 
33 #else
34 
35  T * ptr;
36 
37 #endif
38 
39  // number of elements
40  size_t sz;
41 
43  T get(mem_id i)
44  {
45  return ptr[i];
46  }
47 
48  public:
49 
51  void set_pointer(void * ptr_)
52  {
53  ptr = static_cast<T *>(ptr_);
54  }
55 
57  void * get_pointer()
58  {
59  return ptr;
60  }
61 
63  T & operator[](mem_id i)
64  {
65  return ptr[i];
66  }
67 
70 
78  memory_array(void * ptr, size_t sz, bool init)
79  : ptr(static_cast<T *>(ptr))
80  {
81 #ifdef SE_CLASS2
82  check_valid(ptr,sz);
83 #endif
84 
85  // Initialize the constructors
86 
87  if (init == false)
88  new (ptr)T[sz];
89 
90  this->sz = sz;
91  };
92 
99  {
100  // Call the destructor of every objects
101  for (size_t i = 0 ; i < sz ; i++)
102  {
103  (&ptr[i])->~T();
104  }
105  };
106 };
107 
108 
109 #endif
memory_array()
Default constructor.
void set_pointer(void *ptr_)
Set the internal pointer to the indicated chunk of memory.
memory_array(void *ptr, size_t sz, bool init)
Memory array constructor.
This class give a representation to a chunk or memory.
void * get_pointer()
Return the pointer.
T & operator[](mem_id i)
operator[]
~memory_array()
Destructor.