| 212 | } |
| 213 | |
| 214 | int |
| 215 | Cache::get_data(const int index, Qfloat** data, int len) |
| 216 | { |
| 217 | head_t* h = &head[index]; |
| 218 | |
| 219 | if (h->len) |
| 220 | lru_delete(h); |
| 221 | |
| 222 | int more = len - h->len; |
| 223 | |
| 224 | if (more > 0) { |
| 225 | // free old space |
| 226 | while (size < more) { |
| 227 | head_t* old = lru_head.next; |
| 228 | lru_delete(old); |
| 229 | free(old->data); |
| 230 | size += old->len; |
| 231 | old->data = nullptr; |
| 232 | old->len = 0; |
| 233 | } |
| 234 | |
| 235 | // allocate new space |
| 236 | h->data = static_cast<Qfloat*>(realloc(h->data, sizeof(Qfloat) * len)); |
| 237 | |
| 238 | size -= more; |
| 239 | |
| 240 | swap(h->len, len); |
| 241 | } |
| 242 | |
| 243 | lru_insert(h); |
| 244 | |
| 245 | *data = h->data; |
| 246 | return len; |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | Cache::swap_index(int i, int j) |
no test coverage detected