Use Bit Fields to Store Significant Amounts of Data Optimally

Both C and C++ enable you to store and access data directly in the tiniest possible unit: a bit. This technique is required when dealing with a huge amount of data, for example, on databases containing dozens of millions of records; when memory is scarce (i.e., in embedded systems, hand watch phone books) or when transmitted via a slow communication link. In the following example, only one byte is used to store a person’s data, instead of three which would have been needed otherwise. When multiplied by a factor of 10 million, for example a national registry’s records, it does make a difference:

 struct PersonalData {unsigned int marital_stat: 3;  //3 bitsunsigned int gender: 1;		//1 bitunsigned int children: 4;	//4 bits};enum Stat {single, married, divorced, widowed, separated};enum Gender {male, female};void f () {	PersonalData pd [1000]; //1000 bytes	//fill with data	pd[0].marital_stat = married;	pd[0].gender = female;	pd[0].children = 2; //ints can be used but its the user's
//responsibilty to avoid overflow. Enum's are
//safe, though //...etc. TrasmitToClient(&pd[0], 1000); //transmit all of them }
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may