Ticket #1694: pes_allocator.patch
File pes_allocator.patch, 2.4 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/mpeg/pespacket.cpp
135 145 static vector<unsigned char*> free4096; 136 146 static map<unsigned char*, bool> alloc4096; 137 147 138 #define BLOCKS188 1000148 #define BLOCKS188 512 139 149 static unsigned char* get_188_block() 140 150 { 141 if ( !free188.size())151 if (free188.empty()) 142 152 { 143 153 mem188.push_back((unsigned char*) malloc(188 * BLOCKS188)); 144 154 free188.reserve(BLOCKS188); 155 unsigned char* block_start = mem188.back(); 145 156 for (uint i = 0; i < BLOCKS188; ++i) 146 free188.push_back(i*188 + mem188.back());157 free188.push_back(i*188 + block_start); 147 158 } 148 159 149 160 unsigned char *ptr = free188.back(); … … 161 172 static void return_188_block(unsigned char* ptr) 162 173 { 163 174 alloc188.erase(ptr); 164 if (alloc188.size())165 free188.push_back(ptr);166 else175 free188.push_back(ptr); 176 // free the allocator only if more than 1 block was used 177 if (alloc188.empty() && mem188.size() > 1) 167 178 { 168 179 vector<unsigned char*>::iterator it; 169 180 for (it = mem188.begin(); it != mem188.end(); ++it) … … 174 185 } 175 186 } 176 187 177 #define BLOCKS4096 256188 #define BLOCKS4096 128 178 189 static unsigned char* get_4096_block() 179 190 { 180 if ( !free4096.size())191 if (free4096.empty()) 181 192 { 182 193 mem4096.push_back((unsigned char*) malloc(4096 * BLOCKS4096)); 183 194 free4096.reserve(BLOCKS4096); 195 unsigned char* block_start = mem4096.back(); 184 196 for (uint i = 0; i < BLOCKS4096; ++i) 185 free4096.push_back(i*4096 + mem4096.back());197 free4096.push_back(i*4096 + block_start); 186 198 } 187 199 188 200 unsigned char *ptr = free4096.back(); … … 200 212 static void return_4096_block(unsigned char* ptr) 201 213 { 202 214 alloc4096.erase(ptr); 203 if (alloc4096.size()) 204 { 205 free4096.push_back(ptr); 215 free4096.push_back(ptr); 206 216 207 217 #if 0 // enable this to debug memory leaks 208 218 cerr<<alloc4096.size()<<" 4096 blocks remain"<<endl; … … 220 230 cerr<<endl; 221 231 } 222 232 #endif 223 } 224 else 233 234 // free the allocator only if more than 1 block was used 235 if (alloc4096.empty() && mem4096.size() > 1) 225 236 { 226 237 vector<unsigned char*>::iterator it; 227 238 for (it = mem4096.begin(); it != mem4096.end(); ++it)