MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / NumToNiceStr

Function NumToNiceStr

vulkaninfo/vulkaninfo.cpp:445–465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443#define kBufferSize 32
444
445std::string NumToNiceStr(const size_t sz) {
446 const char prefixes[] = "KMGTPEZY";
447 char buf[kBufferSize];
448 int which = -1;
449 double result = (double)sz;
450 while (result > 1024 && which < 7) {
451 result /= 1024;
452 ++which;
453 }
454
455 char unit[] = "\0i";
456 if (which >= 0) {
457 unit[0] = prefixes[which];
458 }
459#ifdef _WIN32
460 _snprintf_s(buf, kBufferSize * sizeof(char), kBufferSize, "%.2f %sB", result, unit);
461#else
462 snprintf(buf, kBufferSize, "%.2f %sB", result, unit);
463#endif
464 return std::string(buf);
465}
466
467std::string append_human_readable(VkDeviceSize memory) {
468 return std::to_string(memory) + " (" + to_hex_str(memory) + ") (" + NumToNiceStr(static_cast<size_t>(memory)) + ")";

Callers 1

append_human_readableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected