ProgrammingHard
A bit array for flags of 10^9 items is held as one byte per item. What is the memory use, and is it fast enough in typical limits?
- A. About 1 GB, which is usually too much, so pack the flags into bits (about 125 MB)
- B. About 1 MB, which is always fine
- C. About 4 GB, which is fine with a fast disk
- D. About 8 bytes total, since bytes are shared
Correct answer: A. About 1 GB, which is usually too much, so pack the flags into bits (about 125 MB)
One byte per flag uses 10^9 bytes, about 1 GB. Packing eight flags per byte reduces it to 125 MB.
More C Programming questions
- struct P { char a; int b; char c; }; printf("%zu", sizeof(struct P)); What is printed with 4-byte int and natural alignment?
- struct P { char a; int b; }; printf("%zu", offsetof(struct P, b)); What is printed with 4-byte int and natural alignment (stddef.h…
- struct R { int v; struct R next; }; struct R c = {3, NULL}, b = {2, &c}, a = {1, &b}; printf("%d", a.next->next->v); What is printed?
- struct Pt { int x, y; }; struct Pt pts[3] = {{1, 2}, {3, 4}, {5, 6}}; struct Pt p = pts + 1; printf("%d %d", p->x, (p - pts)); What is…
- struct Item { int id; int qty; }; struct Item a[2] = {{1, 5}, {2, 7}}; struct Item b = a[1]; b.qty = 0; printf("%d %d", a[1].qty, b.qty)…
- struct Item { int id; int qty; }; struct Item a[3] = {{1, 2}, {3, 4}}; printf("%d", a[2].qty); What is printed?