OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
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 {
28  T * ptr;
29 
31  T get(mem_id i)
32  {
33  return ptr[i];
34  }
35 
36  public:
37 
39  void set_pointer(void * ptr_)
40  {
41  ptr = static_cast<T *>(ptr_);
42  }
43 
45  void * get_pointer()
46  {
47  return ptr;
48  }
49 
51  T & operator[](mem_id i)
52  {
53  return ptr[i];
54  }
55 
58 
66  memory_array(void * ptr, size_t sz, bool init)
67  : ptr(static_cast<T *>(ptr))
68  {
69 #ifdef SE_CLASS2
70  check_valid(ptr,sz);
71 #endif
72 
73  // Initialize the constructors
74 
75  if (init == false)
76  new (ptr)T[sz];
77  };
78 };
79 
80 
81 #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[]
T * ptr
Internal pointer.