Checks whether the available RAM is larger than the requested allocation. The check is only performed for requests of at least 1 MB to avoid overhead for small allocations.
| 555 | /// Checks whether the available RAM is larger than the requested allocation. |
| 556 | /// The check is only performed for requests of at least 1 MB to avoid overhead for small allocations. |
| 557 | bool check_available_RAM(size_t size) { |
| 558 | const size_t MIN_MB = 1024 * 1024; // 1 MB in Bytes |
| 559 | |
| 560 | if (size > MIN_MB) { |
| 561 | size_t ram_size = get_available_RAM(); |
| 562 | |
| 563 | if (size > ram_size) { |
| 564 | double value_1, value_2; |
| 565 | const char *unit_1, *unit_2; |
| 566 | |
| 567 | bytes_to_readable(size, &value_1, &unit_1); |
| 568 | bytes_to_readable(ram_size, &value_2, &unit_2); |
| 569 | LASMessage(LAS_WARNING, "failed to allocate %.0f%s memory as only approx. %.0f%s free reported. An error may occur", value_1, unit_1, value_2, unit_2); |
| 570 | return true; |
| 571 | } |
| 572 | } |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | /// extension of the realloc function to check memory allocation errors |
| 577 | void* realloc_las(void* ptr, size_t size) { |
no test coverage detected