aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/MyBuffer2.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/MyBuffer2.h
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'CPP/Common/MyBuffer2.h')
-rw-r--r--CPP/Common/MyBuffer2.h39
1 files changed, 30 insertions, 9 deletions
diff --git a/CPP/Common/MyBuffer2.h b/CPP/Common/MyBuffer2.h
index 23394f8..1ec8ffb 100644
--- a/CPP/Common/MyBuffer2.h
+++ b/CPP/Common/MyBuffer2.h
@@ -65,13 +65,13 @@ class CAlignedBuffer1
65public: 65public:
66 ~CAlignedBuffer1() 66 ~CAlignedBuffer1()
67 { 67 {
68 ISzAlloc_Free(&g_AlignedAlloc, _data); 68 z7_AlignedFree(_data);
69 } 69 }
70 70
71 CAlignedBuffer1(size_t size) 71 CAlignedBuffer1(size_t size)
72 { 72 {
73 _data = NULL; 73 _data = NULL;
74 _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); 74 _data = (Byte *)z7_AlignedAlloc(size);
75 if (!_data) 75 if (!_data)
76 throw 1; 76 throw 1;
77 } 77 }
@@ -92,21 +92,23 @@ public:
92 CAlignedBuffer(): _data(NULL), _size(0) {} 92 CAlignedBuffer(): _data(NULL), _size(0) {}
93 ~CAlignedBuffer() 93 ~CAlignedBuffer()
94 { 94 {
95 ISzAlloc_Free(&g_AlignedAlloc, _data); 95 z7_AlignedFree(_data);
96 } 96 }
97 97
98 /*
98 CAlignedBuffer(size_t size): _size(0) 99 CAlignedBuffer(size_t size): _size(0)
99 { 100 {
100 _data = NULL; 101 _data = NULL;
101 _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); 102 _data = (Byte *)z7_AlignedAlloc(size);
102 if (!_data) 103 if (!_data)
103 throw 1; 104 throw 1;
104 _size = size; 105 _size = size;
105 } 106 }
107 */
106 108
107 void Free() 109 void Free()
108 { 110 {
109 ISzAlloc_Free(&g_AlignedAlloc, _data); 111 z7_AlignedFree(_data);
110 _data = NULL; 112 _data = NULL;
111 _size = 0; 113 _size = 0;
112 } 114 }
@@ -120,10 +122,10 @@ public:
120 { 122 {
121 if (!_data || size != _size) 123 if (!_data || size != _size)
122 { 124 {
123 ISzAlloc_Free(&g_AlignedAlloc, _data); 125 z7_AlignedFree(_data);
124 _size = 0; 126 _size = 0;
125 _data = NULL; 127 _data = NULL;
126 _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); 128 _data = (Byte *)z7_AlignedAlloc(size);
127 if (_data) 129 if (_data)
128 _size = size; 130 _size = size;
129 } 131 }
@@ -133,10 +135,29 @@ public:
133 { 135 {
134 if (!_data || size > _size) 136 if (!_data || size > _size)
135 { 137 {
136 ISzAlloc_Free(&g_AlignedAlloc, _data); 138 z7_AlignedFree(_data);
137 _size = 0; 139 _size = 0;
138 _data = NULL; 140 _data = NULL;
139 _data = (Byte *)ISzAlloc_Alloc(&g_AlignedAlloc, size); 141 _data = (Byte *)z7_AlignedAlloc(size);
142 if (_data)
143 _size = size;
144 }
145 }
146
147 // (size <= size_max)
148 void AllocAtLeast_max(size_t size, size_t size_max)
149 {
150 if (!_data || size > _size)
151 {
152 z7_AlignedFree(_data);
153 _size = 0;
154 _data = NULL;
155 if (size_max < size) size_max = size; // optional check
156 const size_t delta = size / 2;
157 size += delta;
158 if (size < delta || size > size_max)
159 size = size_max;
160 _data = (Byte *)z7_AlignedAlloc(size);
140 if (_data) 161 if (_data)
141 _size = size; 162 _size = size;
142 } 163 }