当前位置:网站首页>Space saving "bit segments" in C language“
Space saving "bit segments" in C language“
2022-07-20 08:37:00 【This is iNEvitable】
Catalog
2. Bit segment memory allocation
3. The cross platform problem of bit segment
1. What is a bit segment ?
Bit segments are used to describe complex objects , When creating a member list, some objects don't need much space , So save space by setting bit segments , As its name suggests , Segment by bit .
Grammatical rules :
1. Bit segment Members must be plastic families int、unsigned int or signed int 、char、unsigned char or signed char.
2. Bit segment After the member name There is one The colon And a Numbers .
struct A
{
int a:2;
int b:5;
int c:10;
int d:30;
};
2. Bit segment memory allocation
You can see , The meaning of numbers is The size of the space , In bits , Create a space from the type of the first member variable , other Next to each other Bit segment of member Variable Use this space together , Use the set number of digits to occupy .
The space of the bit segment is based on 4 Bytes ( int ) perhaps 1 Bytes ( char ) Of Way to open up Of , Namely It belongs to the plastic family .
Bit segments involve many uncertainties , Bit segments are not cross platform , Pay attention to portable program should avoid using bit segment .
Using examples :
3. The cross platform problem of bit segment
1. int It's uncertain whether a bit segment is treated as a signed number or an unsigned number .
2. The number of the largest bits in the bit segment cannot be determined .(16 The machine is the largest 16,32 The machine is the largest 32, It's written in 27, stay 16 A bit of the machine will go wrong .
3. The members in the bit segment are allocated from left to right in memory , Or right to left allocation criteria have not yet been defined .
4. When a structure contains two bit segments , The second segment is relatively large , Cannot hold the remaining bits of the first bit segment , Whether to discard the remaining bits or to use , This is uncertain .VS Will abandon and open up a new space .
4. Application of bit segment
After the above simple understanding , Bit segment can save a lot of space , As many programs look small , In fact, there are variable types in the source code that can meet the conditions, which can save most of the useless space , This way of saving space is also one of them .
边栏推荐
- Esp8266 -- temperature and humidity monitoring code dht-11 (web page display)
- 枚举(enum)奇妙的使用、联合体(共用体union)对空间节省的巧妙
- 2022-07-18 第五小组 修身课 学习笔记(every day)
- The longest common subsequence of order 2 and order n
- 第七十四篇:机器学习优化方法及超参数设置综述
- shell脚本编程
- 60-[重点]Object.defineProperty的set方法
- 92-兄弟组件间的传值问题
- A long detailed explanation of C language dynamic memory management
- My first blog
猜你喜欢
位运算——异或
学习日记-指针专题
C language to achieve basic version of mine sweeping
C language custom types: structure, enumeration, union
A long detailed explanation of C language dynamic memory management
数据的表示和运算
Pytorch target detection data enhances the mixing of cutmix and mixup
2022-07-18 第五小组 修身课 学习笔记(every day)
c语言指针重难点
69-简单聊天对话框-拓展-撤回功能
随机推荐
My first blog
[智力题]面试智力题
85-props的第二个写法
Student achievement management system (C language)
【学习笔记】Unreal(虚幻)4引擎入门(三)
Interval coverage problem
第五十八篇:VS调试出现“覆盖。。。。是/N:否/A:全部)??”
Custom type: structure, bit segment, enumeration, union
C语言中动态内存的开辟
Dynamic memory request
【学习笔记】“机房预约系统”作业复盘及问题总结
92-兄弟组件间的传值问题
字符串函数和内存操作函数
Easier to use C language entry-level cheese (1) data types, variables and constants, strings + escape characters + comments (super detailed)
Special topic of structure
ES6之Object.defineProperty 和 Proxy 区别
steam文件夹移动后游戏需要重新安装怎么办
JS如何判断当前日期是否在某个范围内
基数排序(桶排序)
Pytorch target detection coco API explanation data generation