How to set a buffer size to 2 petabytes in C

1 Answer

0 votes
// A petabyte (binary) is:
              
// 1 PiB = 2⁵⁰ bytes = 1,125,899,906,842,624 bytes
// A petabyte (decimal) is:
// 1 PB = 1,000,000,000,000,000 bytes

#include <stdio.h>
#include <locale.h>

#define PETABYTE (1ULL << 50)              // 1 PiB = 2^50 bytes
#define PETABYTE_DEC 1000000000000000ULL   // 1 PB  = 10^15 bytes

int main(void) {
    // Set buffer size to 2 PiB (binary petabytes)
    size_t buffer_size = 2 * PETABYTE;

    printf("Buffer size (binary 2 PiB):  %zu bytes\n", buffer_size);
    
     // Enable locale so %'llu prints commas (glibc only)
    setlocale(LC_NUMERIC, "");
    
    printf("Buffer size (binary 2 PiB):  %'llu bytes\n", buffer_size);

    return 0;
}


/*
run:

Buffer size (binary 2 PiB):  2251799813685248 bytes
Buffer size (binary 2 PiB):  2,251,799,813,685,248 bytes

*/

 



answered 2 hours ago by avibootz
...