Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce000e5

Browse files
Introduce size_ptr to store pointer and size of the object, and VLATO_prt to store pointers to Variable Length Array-Terminated objects
1 parente53d8ed commitce000e5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎blobstamper/helpers.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,46 @@ max precision
7676
"%.999g", __val);
7777
}
7878

79+
80+
template<classT>classsized_ptr
81+
{
82+
private:
83+
T* _ptr{nullptr};
84+
size_t _size;
85+
public:
86+
87+
operator T*()const {return _ptr;};
88+
size_tsize() {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<classT,classArrayT>classVLATO_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_tlength() {return _length;};
104+
size_tsize() {returnsizeof(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<classT,classArrayT>
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+
79121
#endif/*HELPERS_H*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp