计算机编程基础
小姚同志
这个作者很懒,什么都没留下…
展开
-
多大范围内的整数可以用浮点数精确表示
转载自https://airguanz.github.io/2019/11/20/float-to-int-exact-range.html我们知道,IEEE 754中的浮点数是对实数的近似表示,其取值密度在越远离0的地方越稀疏。那么,究竟在多远处浮点数会无法精确地cast到整数呢?本文对此进行了实验和分析。实验代码很简单:int main(){ for(int i = 0; i < std::numeric_limits<int>::max(); ++..转载 2022-02-27 21:23:31 · 1546 阅读 · 0 评论 -
utf-8的中文汉字
从字符编码讲起。1、美国人首先对其英文字符进行了编码,也就是最早的ascii码,用一个字节的低7位来表示英文的128个字符,高1位统一为0;2、后来欧洲人发现尼玛你这128位哪够用,比如我高贵的法国人字母上面的还有注音符,这个怎么区分,得,把高1位编进来吧,这样欧洲普遍使用一个全字节进行编码,最多可表示256位。欧美人就是喜欢直来直去,字符少,编码用得位数少;3、但是即使位数少,不同国家地区用不同的字符编码,虽然0--127表示的符号是一样的,但是128--255这一段的解释完全乱套了,即使...原创 2020-10-28 16:57:04 · 2732 阅读 · 0 评论 -
C实现CPU大小端判断
C实现CPU大小端判断所谓大端就是指高位值在内存中放低位地址,所谓小端是指低位值在内存中放低位地址。比如 0x12345678 在大端机上是 12345678,在小端机上是 78564312,而一个主机是大端还是小端要看CPU类型以及运行在上面的操作系统。同一款CPU在不同的操作系统使用的大小端情况是不同的。当然我们通常使用的 x86 + windows是小端。//测试大小端一般使用 u...转载 2019-02-19 09:52:19 · 108 阅读 · 0 评论 -
内存地址对齐的思考和总结
内存地址对齐,是一种在计算机内存中排列数据、访问数据的一种方式,包含了两种相互独立又相互关联的部分:基本数据对齐和结构体数据对齐。当今的计算机在计算机内存中读写数据时都是按字(word)大小块来进行操作的(在32位系统中,数据总线宽度为32,每次能读取4字节,地址总线宽度为32,因此最大的寻址空间为2^32=4GB,但是最低2位A[0],A[1]是不用于寻址,A[2-31]才能存储器相连,因此只能...转载 2019-02-19 09:52:42 · 1248 阅读 · 1 评论 -
Eliminate False Sharing
Eliminate False SharingBy Herb Sutter, May 14, 2009 Stop your CPU power from invisibly going down the drainIn two previous articles I pointed out the performance issue of false sharing (aka ca...原创 2018-12-22 09:58:48 · 680 阅读 · 0 评论 -
The new C++ 11 rvalue reference && and why you should start using it
The new C++ 11 rvalue reference && and why you should start using itIntroduction This is an attempt to explain new && reference present in latest versions of c...翻译 2018-12-22 09:59:06 · 653 阅读 · 0 评论 -
C++ Explained: Object initialization and assignment, lvalues and rvalues, copy and move semantics an
C++ Explained: Object initialization and assignment, lvalues and rvalues, copy and move semantics and the copy-and-swap idiomFebruary 27, 2013Leave a commentGo to comments 3 Votes...翻译 2018-12-22 09:59:44 · 371 阅读 · 0 评论 -
How L1 and L2 CPU Caches Work, and Why They’re an Essential Part of Modern Chips
How L1 and L2 CPU Caches Work, and Why They’re an Essential Part of Modern ChipsBy Joel Hruska on August 30, 2018 at 1:30 pm CommentFacebook Twitter Google Plus Reddit Hacker News Flipboard ...原创 2018-12-22 10:00:03 · 389 阅读 · 0 评论 -
CPU, cores, threads and cache
Please let me know if I'm providing the overview at the wrong level of detail :)1+2)Physical core - the actual hardware executing the codeLogical core - what OS sees as some (possibly virtualized) ...原创 2018-12-22 10:01:25 · 528 阅读 · 0 评论