File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -76,4 +76,46 @@ max precision
76
10000
td>76
" %.999g" , __val);
77
77
}
78
78
79
+
80
+ template <class T > class sized_ptr
81
+ {
82
+ private:
83
+ T* _ptr{nullptr };
84
+ size_t _size;
85
+ public:
86
+
87
+ operator T*() const {return _ptr;};
88
+ size_t size () {return _size;};
89
+ sized_ptr (T* ptr, size_t size): _ptr{ptr}, _size{size} {};
90
+ ~sized_ptr () {if (_ptr) free (_ptr);};
91
+ };
92
+
93
+ template <class T , class ArrayT > class VLATO_ptr
94
+ {
95
+ private:
96
+ T* _ptr{nullptr };
97
+ size_t _length;
98
+ public:
99
+
100
+ operator T*() const {return _ptr;};
101
+ operator sized_ptr<T>() {sized_ptr<T> res (_ptr,size ()); _ptr=NULL ; return res;};
102
+
103
+ size_t length () {return _length;};
104
+ size_t size () {return sizeof (T) + _length * sizeof (ArrayT);};
105
+ VLATO_ptr (size_t length);
106
+ VLATO_ptr (T* ptr, size_t length): _ptr{ptr}, _length{length} {};
107
+ ~VLATO_ptr () {if (_ptr) free (_ptr);}
108
+ };
109
+
110
+
111
+ template <class T , class ArrayT >
112
+ VLATO_ptr<T,ArrayT>::VLATO_ptr(size_t length)
113
+ {
114
+ _ptr = (T*) malloc (sizeof (T) + sizeof (ArrayT) * length);
115
+ _length = length;
116
+ }
117
+
118
+
119
+
120
+
79
121
#endif /* HELPERS_H*/
You can’t perform that action at this time.
0 commit comments