1 | // LAF Base Library |
2 | // Copyright (c) 2001-2016 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include <string> |
12 | #include <cstdio> |
13 | |
14 | namespace base { |
15 | |
16 | using namespace std; |
17 | |
18 | string get_pretty_memory_size(size_t memsize) |
19 | { |
20 | char buf[256]; |
21 | |
22 | if (memsize < 1000) { |
23 | sprintf(buf, "%lu bytes" , memsize); |
24 | } |
25 | else if (memsize < 1000*1000) { |
26 | sprintf(buf, "%0.1fK" , memsize/1024.0f); |
27 | } |
28 | else { |
29 | sprintf(buf, "%0.1fM" , memsize/(1024.0f*1024.0f)); |
30 | } |
31 | |
32 | return buf; |
33 | } |
34 | |
35 | } // namespace base |
36 | |