当前位置:网站首页>Redis中的SDS理解
Redis中的SDS理解
2022-06-30 03:22:00 【阿联爱学习】
1.C语言中的char*会存在什么问题?
- 会以'/0'作为字符串的结束符,所以无法存储'/0'字符。
- len(String)操作需要O(n)的时间复杂度。
- strcat(des,src)追加的时候,会进行遍历到des末尾在进行追加,时间复杂度高。
- char*默认使用内存对齐的方式存储,浪费内存空间。
2.Redis自定义SDS解读?
- SDS:Simple Dynamic String,简单动态的String,类似于Go中的slice。数据结构如下所示:
2.SDS存储实际字符串的长度和实际内存大小,可以更加方便的len()和字符串的追加操作、
3.struct __attribute__ ((__packed__))通过紧凑的方式进行存储可以节省内存空间,flags用于标志用什么长度进行存储。下面是flags=sdshdr8的数据结构。
struct __attribute__ ((__packed__)) sdshdr8 { uint8_t len; /* 字符数组现有长度*/ uint8_t alloc; /* 字符数组的已分配空间,不包括结构体和\0结束字符*/ unsigned char flags; /* SDS类型*/ char buf[]; /*字符数组*/ };
边栏推荐
- Federal learning: dividing non IID samples by Dirichlet distribution
- Mysqldump principle
- Sorting method of administrative route code letter + number
- DC/DC变换器轻载时三种工作模式的原理及优缺点
- Auto. JS learning notes 15:ui interface basics of autojs Chapter 2
- 1148_ Makefile learning_ Targets, variables, and wildcards in makefile
- TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
- C#【高级篇】 C# 泛型(Generic)【需进一步补充:泛型接口、泛型事件的实例】
- mysql 主从数据库同步失败的原因
- Add a custom button to jvxetable
猜你喜欢
Mysql提取表字段中的字符串
Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
自定义MVC的使用
第2章 控制结构和函数(编程题)
Federal learning: dividing non IID samples by Dirichlet distribution
[practical skills] how to write agile development documents
golang bilibili直播彈幕姬
Golang BiliBili live broadcast bullet screen
HOOK Native API
Redis高并发分布式锁(学习总结)
随机推荐
Global and Chinese market of bronze valves 2022-2028: Research Report on technology, participants, trends, market size and share
C#【高级篇】 C# 泛型(Generic)【需进一步补充:泛型接口、泛型事件的实例】
Differences between comparable and comparator
Auto. JS learning notes 15:ui interface basics of autojs Chapter 2
Global and Chinese markets for active transdermal drug delivery devices 2022-2028: Research Report on technology, participants, trends, market size and share
How to realize remote collaborative office, keep this strategy!
[QT] QMap使用详解
On the role of database tables
Comparable和Comparator的区别
专升本高数(四)
Shell counts all strings before the last occurrence of a string
On the optimization and use of idea
Realization of BFS in C language by storing adjacency matrix of graph
Neo4j--- performance optimization
WPF initialized event in The reason why binding is not triggered in CS
Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
广播模块代码在autojs4.1.1版本运行正常,但在pro7.0版本上运行报错(未解决)
【十分钟】manim安装 2022
DC/DC变换器轻载时三种工作模式的原理及优缺点
Compile a DLL without import table