A bit, on average

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Moderators General, Prelates

User avatar
Posts: 268
Joined: Fri Sep 21, 2012 12:53 am UTC
Location: The Way of the Hedgehog

A bit, on average

Postby tms » Wed Jul 05, 2017 11:31 pm UTC

What can be said about the average value of bits that are refreshed - or stored as it may - in RAM and in the CPU cache and registers? How far from even can you expect to see and what typically affects it?
- No, son. I said 'duck'.
- Duck duck duck duck! Duck duck duck duck!

Posts: 475
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: A bit, on average

Postby Tub » Thu Jul 06, 2017 1:49 pm UTC

It depends on the data that is stored. Compressed or encrypted data should appear uniformly random, i.e. have roughly equal parts 0 and 1. Other data often favors 0: in ASCII-text, the leading bit of each character is always 0 (but most small letters have the second bit as 1, so it almost evens out). Programmers may use 64-bit integers to store values as low as 100, thus having >50 leading zeros. Depending on the address space layout, pointers may favor either 0 or 1.
Unused memory is initialized to 0 by the operating system, so anything reserved but not used (like padding bytes for alignment) is usually 0.

I just took a core dump of my running firefox, which has 91.8% zero, 8.2% one - but that's a dump of its address space, including many unused memory regions filled with 0. If you were to dump physical memory, that ratio would be a lot closer to 50/50.

User avatar
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: A bit, on average

Postby Jplus » Wed Aug 30, 2017 10:07 pm UTC

Addition to what Tub wrote: virtual memory may be compressed in RAM. This increases the entropy of the data, so you expect a ratio closer to 50:50 in the compressed pages. However, such compression is never applied to all of the memory at the same time, because a process can't use a page while it is in the compressed state. Recent macs do this as a way to postpone swapping. Perhaps Windows 10 is doing it too.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined


Return to “Computer Science”

Who is online

Users browsing this forum: No registered users and 11 guests