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

Function bytes_to_readable

src/mydefs.cpp:512–529  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

510
511/// Converts a byte count into a human-readable value and unit
512void bytes_to_readable(size_t bytes, double* value_out, const char** unit_out) {
513 double value = (double)bytes;
514 const char* unit = "Bytes";
515
516 if (bytes >= (1ULL << 30)) { // 1 GB
517 value = value / (1ULL << 30);
518 unit = "GB";
519 } else if (bytes >= (1ULL << 20)) { // 1 MB
520 value = value / (1ULL << 20);
521 unit = "MB";
522 } else if (bytes >= (1ULL << 10)) { // 1 KB
523 value = value / (1ULL << 10);
524 unit = "KB";
525 }
526
527 if (value_out) *value_out = value;
528 if (unit_out) *unit_out = unit;
529}
530
531/// Returns the amount of currently available physical RAM in bytes
532/// 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