
C
自驱
ALOHA HEJA HE
展开
-
【golang map】 深入了解map内部存储协议
/ 我们这样做了,键可能会返回 0 或 2 次)。// 语义上,我们永远不会在它们的桶中移动键(如果。// 如果超过 8 个键散列到一个桶,我们链上。// 放入一个桶数组。// 当哈希表增长时,我们分配一个新数组。// 按遍历顺序返回键(桶#,然后溢出。// 8 个键/元素对。// 用于选择一个桶。// 链序,然后是桶索引)。// 每个散列的高位位以区分条目。// 从旧桶数组复制到新桶数组。// 旧表,如果桶必须检查新表。// 映射迭代器遍历桶数组和。// 增长表,迭代器继续迭代。// 在单个存储桶中。..原创 2022-08-09 21:21:55 · 385 阅读 · 0 评论 -
【Bit】求一个整数abs值,注意:不能用分支
解:int v; // we want to find the absolute value of vunsigned int r; // the result goes here int const mask = v >> sizeof(int) * CHAR_BIT - 1;r = (v + mask) ^ mask;Patented variation:r = (v ^ mask) - mask;源码: int v = -原创 2022-01-30 14:39:53 · 616 阅读 · 0 评论 -
【redis】3.0 lpush rpush 源码详解
1 命令表{"rpush",rpushCommand,-3,"wm",0,NULL,1,1,1,0,0}, {"lpush",lpushCommand,-3,"wm",0,NULL,1,1,1,0,0},2 放在前面ZIPLIST and LINKEDLIST/* 空白 ziplist 示例图area |<---- ziplist header ---->|<-- end -->|size 4 bytes 4 bytes原创 2022-01-29 17:29:23 · 1356 阅读 · 0 评论 -
【redis】3.0 incr decr 源码
1. cmd incr decr 命令// 命令Tablestruct redisCommand redisCommandTable[] = { {"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, {"set",setCommand,-3,"wm",0,NULL,1,1,1,0,0}, ... {"incr",incrCommand,2,"wm",0,NULL,1,1,1,0,0}, {"decr",decrCommand,2原创 2022-01-13 10:40:20 · 271 阅读 · 0 评论 -
【C】strtoll 函数用例
int main() { unsigned long s = CHAR_BIT * sizeof(1l); // bit size; must be power of 2 unsigned long mask = ~0UL; printf("s = %lu \n", s); pb(s); printf("s = %lu \n", mask); pb(mask); unsigned long i = rev(1l); printf("s..原创 2022-01-12 10:56:19 · 645 阅读 · 0 评论 -
【技巧】将数组均匀拆分或者一行数据拆等分多行,如何计算最终分组数或者行数?
参考: redis 源码:refreshMultiLine line:563 // redis/deps/linenoise/linenoise.c计算行数容量: int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */故: rows = (total_len + row_len -1) / row_len ;...原创 2021-12-03 13:41:47 · 311 阅读 · 0 评论 -
【redis】 redis 6.0 驱逐key Pool计算方式 如何完成采样? 阅读源码 evictionPoolPopulate(i, dict, db->dict, p
1.evictionPoolPopulate 算法 // src/evict.c 从左到右 idl time 递增/* This is an helper function for freeMemoryIfNeeded(), it is used in order * to populate the evictionPool with a few entries every time we want to * expire a key. Keys with idle time smaller...原创 2021-12-03 23:45:00 · 630 阅读 · 0 评论 -
【redis】6.0 源码阅读: Handle the maxmemory directive
processCommand方法调用链路:networking.c【readQueryFromClient-->processInputBuffer-->processCommandAndResetClient-->processCommand】 -->freeMemoryIfNeededAndSafe -->freeMemoryIfNeeded // evict.c -->计算需要释放内存量 -->根据配置的驱逐策略来生释放缓存: server..原创 2021-12-02 23:45:00 · 624 阅读 · 0 评论 -
【goland】内存池设计|缓存设计|大容量无GC缓存--FreeCache
1 简介:Long lived objects in memory introduce expensive GC overhead,With FreeCache,you can cache unlimited number of objects in memorywithout increased latency and degraded throughput.2 FeaturesStore hundreds of millions of entries Zero GC overhead...原创 2021-11-24 15:05:47 · 862 阅读 · 0 评论 -
【redis】从GET命令,深入redis 6.0 渐进式扩容
【redis】从GET命令,深入redis渐进式扩容// Get 命令定义struct redisCommand redisCommandTable[] = { {"module",moduleCommand,-2, "admin no-script", 0,NULL,0,0,0,0,0,0}, {"get",getCommand,2, "read-only fast @string", 0,NULL,1,1,1,0,0,0}, ...原创 2021-11-19 12:10:42 · 510 阅读 · 0 评论 -
【斯坦福大学】图形实验室 二进制文章集合
内容直达:thttp://graphics.stanford.edu/~seander/bithacks.html【斯坦福大学】官网https://www.stanford.edu/原创 2021-11-18 23:00:00 · 350 阅读 · 0 评论 -
redis string robj(int,raw,embstr)之 embstr 类型大小限制44字节由来
1 首先robj所占内存认知16Byte// 总共占用16Byte= 4bit + 4bit + 24bit(lru) + refcount 4Byte + *ptr 8Bytetypedef struct redisObject { unsigned type:4; // 4bit unsigned encoding:4; // 4bit unsigned lru:LRU_BITS; /* LRU time (relative to global ...原创 2021-10-28 11:51:16 · 520 阅读 · 1 评论 -
Redis6.0 sds string--初始化和扩容--详解
1 直接上源码(内部有注释)/* Modify an sds string in-place to make it empty (zero length). * However all the existing buffer is not discarded but set as free space * so that next append operations will not require allocations up to the * number of bytes previo.原创 2021-10-27 17:14:23 · 584 阅读 · 0 评论 -
redis sds 数据结构如何使用 C realloc函数来动态扩容
1 系统函数realloc测试#include <stdio.h>#include <stdlib.h>typedef char *sds;int main() { printf("Hello, World!\n"); char t[] = {'a','b','c','d'}; sds s = t+1; char bb = s[0]; char cc = s[1]; char dd = s[2]; cha.原创 2021-10-27 16:55:35 · 321 阅读 · 0 评论 -
redis 3.0 server初始化PONG -- Mac 系统函数 memcpy 定义
#include <string.h> // /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/secure/_string.h#define memcpy(dest, ...) \ __builtin___memcpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest))#endif参考: redis 3.0 server初始化src..原创 2021-10-26 12:08:13 · 293 阅读 · 0 评论 -
epoll linux 源码github
https://github.com/torvalds/linux/blob/master/fs/eventpoll.c#L1769原创 2021-09-26 18:24:16 · 191 阅读 · 0 评论 -
如何快速判断一个数字为2的n次幂
1 原理原码 & 补码 = 原码 则该数为2的N次幂2 补码在计算机中,负数以其正值的补码形式表达什么叫补码呢?这得从原码,反码说起。原码:一个整数,按照绝对值大小转换成的二进制数,称为原码。比如 00000000 00000000 00000000 00000101 是 5的 原码。反码:将二进制数按位取反,所得的新二进制数称为原二进制数的反码。取反操作指:原为1,得0;原为0,得1。(1变0; 0变1)比如:将00000000 00000000 00000000 0000..原创 2021-09-26 15:38:59 · 336 阅读 · 0 评论 -
redis--计数器和限流器
1 原理和实现限速器的典型用法是限制公开 API 的请求次数,以下是一个限速器实现示例,它将 API 的最大请求数限制在每个 IP 地址每秒钟十个之内:FUNCTION LIMIT_API_CALL(ip)ts = CURRENT_UNIX_TIME()keyname = ip+":"+tscurrent = GET(keyname)IF current != NULL AND current > 10 THEN ERROR "too many requests per s原创 2021-09-26 10:33:46 · 368 阅读 · 0 评论 -
golang syscall 系统调用认知
1 本文整体结构C语言中syscall如何使用? golang中如何使用? syscall 手册 2 C语言中syscall如何使用? #define _GNU_SOURCE #include <unistd.h> #include <sys/syscall.h> #include <sys/types.h> #include <signal.h> ...原创 2021-09-24 11:58:42 · 1561 阅读 · 0 评论 -
【C】hashtable 实现
uthash: a hash table for C structures Any C structure can be stored in a hash table using uthash. Just add aUT_hash_handleto the structure and choose one or more fields in your structure to act as the key. Then use these macros to store, retrieve o...原创 2021-09-13 13:43:55 · 72 阅读 · 0 评论 -
iterative-->forking-->preforked--->threaded 服务架构性能对比
原创 2021-09-10 12:24:58 · 88 阅读 · 0 评论 -
undefined reference to `pthread_detach‘ `pthread_create‘
#include <pthread.h>使用标准库 -lpthread如下:gcc main.c ---> gcc main.c -lpthread原创 2021-09-10 10:07:15 · 971 阅读 · 0 评论 -
C --- wait(NULL) 作用?
Well, sorry, that much is obvious. What you want to know is, probably, what it waits for. The answer is: the termination of a child process. //答案是:终止一个子进程When you create a new child process withfork(), you have no control over when it will be executed ..原创 2021-09-09 16:23:05 · 4100 阅读 · 0 评论 -
The Thundering Herd accept system call
原创 2021-09-09 10:36:15 · 97 阅读 · 0 评论 -
C sigaction 信号系统函数处理
1 sigaction.c ..原创 2021-09-08 10:15:51 · 228 阅读 · 0 评论