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

Function check_available_RAM

LASzip/src/mydefs.cpp:557–574  ·  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

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.
557bool 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
577void* 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