| 495 | } |
| 496 | |
| 497 | void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) |
| 498 | { |
| 499 | size_t max_size; |
| 500 | |
| 501 | if (min_size <= *size) |
| 502 | return ptr; |
| 503 | |
| 504 | max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed); |
| 505 | /* *size is an unsigned, so the real maximum is <= UINT_MAX. */ |
| 506 | max_size = FFMIN(max_size, UINT_MAX); |
| 507 | |
| 508 | if (min_size > max_size) { |
| 509 | *size = 0; |
| 510 | return NULL; |
| 511 | } |
| 512 | |
| 513 | min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size)); |
| 514 | |
| 515 | ptr = av_realloc(ptr, min_size); |
| 516 | /* we could set this to the unmodified min_size but this is safer |
| 517 | * if the user lost the ptr and uses NULL now |
| 518 | */ |
| 519 | if (!ptr) |
| 520 | min_size = 0; |
| 521 | |
| 522 | *size = min_size; |
| 523 | |
| 524 | return ptr; |
| 525 | } |
| 526 | |
| 527 | static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) |
| 528 | { |