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

Function bytes_to_readable

LASzip/src/mydefs.cpp:508–525  ·  view source on GitHub ↗

Converts a byte count into a human-readable value and unit

Source from the content-addressed store, hash-verified

506
507/// Converts a byte count into a human-readable value and unit
508void bytes_to_readable(size_t bytes, double* value_out, const char** unit_out) {
509 double value = (double)bytes;
510 const char* unit = "Bytes";
511
512 if (bytes >= (1ULL << 30)) { // 1 GB
513 value = value / (1ULL << 30);
514 unit = "GB";
515 } else if (bytes >= (1ULL << 20)) { // 1 MB
516 value = value / (1ULL << 20);
517 unit = "MB";
518 } else if (bytes >= (1ULL << 10)) { // 1 KB
519 value = value / (1ULL << 10);
520 unit = "KB";
521 }
522
523 if (value_out) *value_out = value;
524 if (unit_out) *unit_out = unit;
525}
526
527/// Returns the amount of currently available physical RAM in bytes
528/// Note that this value is only a snapshot.

Callers 1

check_available_RAMFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected