Using Bit Fields in Data Optimization
By Danny Kalev, C++ Pro

Networking, file management, cryptography, data compression, and serial port communication are only a few of the application domains in which programmers need to manipulate bits directly. Fortunately, C++ enables you to do that without resorting to assembly programming or inefficient libraries, as I will show in this solution.



The smallest native datatype of C++ is char, which is equivalent to a byte. Yet in certain tasks, programs need to access individual bits of memory directly. How can it be done?



Use bit fields to manipulate individual bits in a struct or a class.

  
Performance Analysis

Introduction
Performance Analysis
Space Optimization

Return to Get Help with C/C++ Page

Return to Main Get Help Page


 




Find Out More



ITWorld.com: Accessing I/O Ports, Part 2

DevX TechTip: The Size of an Enum Type

DevX TechTip: Optimizing Member Alignment

DevX TechTip: Use Bit Fields to Store Significant Amounts of Data Optimally

DevX TechTip: Initializing a Bit Struct

DevX TechTip: Member Alignment

DevX TechTip: The First Rule of Code Optimization

DevX C++ Zone

All DevX 10-Minute Solutions for C/C++





TALK BACK
Which portion of the designing and development stages of your applications is dedicated to optimization, if at all? What is your main concern—speed or space?


Sponsored Links