MCPcopy Create free account
hub / github.com/LASzip/LASzip / check_available_RAM

Function check_available_RAM

src/mydefs.cpp:561–578  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

559/// Checks whether the available RAM is larger than the requested allocation.
560/// The check is only performed for requests of at least 1 MB to avoid overhead for small allocations.
561bool check_available_RAM(size_t size) {
562 const size_t MIN_MB = 1024 * 1024; // 1 MB in Bytes
563
564 if (size > MIN_MB) {
565 size_t ram_size = get_available_RAM();
566
567 if (size > ram_size) {
568 double value_1, value_2;
569 const char *unit_1, *unit_2;
570
571 bytes_to_readable(size, &value_1, &unit_1);
572 bytes_to_readable(ram_size, &value_2, &unit_2);
573 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);
574 return true;
575 }
576 }
577 return false;
578}
579
580/// extension of the realloc function to check memory allocation errors
581void* realloc_las(void* ptr, size_t size) {

Callers 2

realloc_lasFunction · 0.85
malloc_lasFunction · 0.85

Calls 3

get_available_RAMFunction · 0.85
bytes_to_readableFunction · 0.85
LASMessageFunction · 0.85

Tested by

no test coverage detected