Bit/Byte management. Any help?

Lately i have been learning about bit management in cpp and i have some questions pls.

1) Suppose that there are two producers that use shared memory as a buffer. There are n consumers. What issues can arise in this arrangement?



2) Suppose that we wish to pack single byte unsigned numbers into a single unsigned long variable.

a) How many values can be stored?


b) What is the range of the individual numbers?



c) Why is packing values in this way more efficient than handling the values the way we are used to do (classic c++ memory handling)?


1.
Suppose that there are two producers that use shared memory as a buffer. There are n consumers. What issues can arise in this arrangement?

https://en.wikipedia.org/wiki/Producer-consumer_problem

2.
Suppose that we wish to pack single byte unsigned numbers into a single unsigned long variable.

a.) pow(2, sizeof (unsigned long) * std::numeric_limits<unsigned char>::digits) independent values can be stored in a single unsigned long variable.
b.) Each individual packed machine byte has a range of integers in the interval [0, pow(2, sizeof (unsigned char) * std::numeric_limits<unsigned char>::digits) - 1].
c.) It is not necessarily more efficient. In the general case, packing data is an exercise in trading time for memory. This is usually the case, especially if the size of an individual packed datum isn't an integer power of (or is coprime with) the byte size. However, there are many cases IRL where processor-specific optimizations (e.g., SSE) can be applied for speed increases-- for example, when operating on byte strings.
See https://arxiv.org/pdf/1209.2137v6.pdf
Last edited on
Topic archived. No new replies allowed.