自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 资源 (1)
  • 收藏
  • 关注

原创 [rUDP] KCP梳理

背景先介绍下写这篇博客时的背景。无意间就看到了某视频网站需要懂KCP、UDT这类RUDP协议的开发人员,随即投了份简历。因此,这篇博客算是一份对过往知识的梳理,同时也算是一次面试的准备过程。讲真,在当前这个Java横行的年代,坚守C/C++真的不容易;而去搞KCP、UDT等这类RUDP如此底层的玩意,就更少之又少了。至于我为什么会接触RUDP这块,应该也算是研究生阶段的研究方向。当时刚上研究生...

2018-09-11 00:23:04 3800 2

原创 [evpp/muduo/reactor] evpp事件驱动网络库 整体架构梳理 2

序上一篇博文中,我们从用户使用的角度入手,对evpp中TCPServer、TCPClient两大类进行了梳理。接下来,我们再来分析梳理下Listener、Connector两个类的细节。当然,这让我联想起了杨宗纬的那首歌“如果你愿意一层一层一层地剥开我的心,你会发现 你会讶异…”。扯得有点远,让我们进入正题。ListenerListener正如其名,主要是封装和TCPServer ...

2018-09-06 17:15:19 1321

原创 [evpp/muduo/reactor] evpp事件驱动网络库 整体架构梳理

介绍muduo很多人都听说过,那evpp可以理解成是muduo用C++11改写后的升级版。 相比muduo的代码风格,evpp会显得更加现代一点,更讨我们年轻人的喜欢。 作为例子,这里是一段TCP Echo Server的示例代码: std::string addr = "0.0.0.0:9099&

2018-09-03 01:06:16 2940 2

原创 [C++11] 循环引用

前言虽然C++11中的智能指针,一定程度上简化了C++当中的内存管理;但是,shared_ptr<>的使用同时也引出了另一个问题:循环引用。例子让我们先来看一段示例代码。#include <iostream>#include <vector>#include <memory>using namespace std;class pa...

2018-09-30 13:01:52 6874

原创 [Socket] listen()之backlog参数

直奔主题The behavior of the backlog argument on TCP sockets changed with Linux 2.2.Now it specifies the queue length for completely established sockets waiting to beaccepted, instead of the number o...

2018-09-25 10:13:37 690

原创 [Linux] 内存映射IO

前言本科留给我最大的印象,就是大一愣头青死磕APUE。一眨眼,研究生阶段都快结束了。时间过的好快。上研究生之后,慢慢从C转到C++,Linux native API也用的越来越少。趁着最近面试这个机会,赶紧复习一下相关概念。内存映射IO 的优势使用内存映射IO来取代read()和write() 能简化代码逻辑,统一以内存的形式进行处理;特定场景下,能提供更好的性能;内存映射IO 为什...

2018-09-25 00:19:41 544

原创 [STL] vector会自动shrink嘛?

Q(头脑风暴)vector是最常用的STL容器;同时,vector的底层实现会自动处理underlying storage用完的情况,进行扩增。但是,当我们clear()或者erase()掉vector中的部分元素后,vector的underlying storage会自动shrink嘛?A答案是No,std::vector::shrink_to_fit()...

2018-09-24 11:20:42 354

原创 [TCP] Write-Write-Read会有什么问题?

待补充同时包括TCP_CORK 和 TCP_NODELAY

2018-09-23 22:46:11 589

原创 [Linux] 文件描述符和打开文件之间的关系

前言文件描述符、文件句柄和i-node之间的关系,应该是Linux Native Programming的基本功。Golang、C++11写久了之后,这些概念有些淡忘,今天顺便梳理下。铺垫为了搞清楚这当中的关系,我们首先要了解内核维护的3个数据结构:进程级的文件描述符表系统级的打开文件句柄文件系统级的i-node表进程级的文件描述符表单条表项,包括:文件描述符标志,如clo...

2018-09-23 22:36:13 319

原创 [C++] 如何声明一个同迭代器指向元素类型相同的变量?

Q假设算法中要声明一个变量,以"迭代器所指对象的类型”为类型,该怎么办?A1. C++11 auto在C++11当中,可以直接用auto关键词进行声明;auto var = *iter;2. function template的参数推导如果编译器不支持C++11,或者说我想知道auto背后的原理呢?这时候,就需要用上函数模板的参数推导了。template<typename ...

2018-09-21 22:45:40 588

原创 [Golang] timer可能造成的内存泄漏

背景前两天,跟一位学长交流Golang;然后,他突然问我:你知道timer可能造成内存泄漏嘛? 当时,甚是一脸懵逼,毕竟之前写的Agent测了好久,都没发现这个问题啊。今天,就索性了解了下。这里先说下结论,timer的误用可能造成某些等待timer的Goroutine无法正常退出,导致资源无法释放;(ps. 虽然的确算是内存泄漏,但是对于我这种写C出身的人来说,感觉还是怪怪的)接下来进入正题,...

2018-09-19 23:33:45 5123

原创 [Linux] Sleep睡眠线程还是进程?

sleep() causes the calling thread to sleep either until the number ofreal-time seconds specified in seconds have elapsed or until a signalarrives which is not ignored.参考文献:http://man7.org/linux/ma...

2018-09-19 20:36:59 1981

原创 [HTTP] 状态码301和302的区别

301 Permanently Moved 永久重定向被请求的资源永久移动到新位置;将来对此资源的任何引用都应该使用本响应返回的若干个URI之一;如果可能,客户端应当自动把请求地址修改为从服务器返回的地址。除非额外指定,否则这个响应也是可缓存的。301比较常用的场景是使用域名跳转。比如,我们访问 http://www.baidu.com 会跳转到 https://www.baidu.c...

2018-09-19 19:21:34 531

原创 [C++11] 线程安全的单例Singleton

饿汉模式class Singleton {public: static Singleton &GetInstance() { static Singleton instance; return instance; }private: Singleton() = default; Singleton(const Singl...

2018-09-19 00:08:38 284

原创 [C/C++] volatile关键词

Volatile关键字Volatile关键词的第一个特性:易变性。所谓的易变性,在汇编层面反映出来,就是两条语句,下一条语句不会直接使用上一条语句中volatile变量的寄存器内容,而是重新从内存中读取。Volatile关键词的第二个特性:“不可优化”特性。volatile告诉编译器,不要对我这个变量进行各种激进的优化,甚至将变量直接消除,保证程序员写在代码中的指令,一定会被执行。...

2018-09-16 18:42:42 140

原创 [algs] TopK问题

int main() { int N, K; cin >> N >> K; // 请注意,针对TopK(最大的K个元素)问题,我们采用的是末位淘汰的思想; // 末位淘汰后,剩下来的自然而然就是最顶尖的选手; // 因此,这里用的是MinPQ,小根堆; priority_queue<int, vector<int...

2018-09-16 16:14:51 126

原创 [GeeksForGeeks] Bin Packing Problem (Minimize number of used Bins)

Given n items of different weights and bins each of capacity c, assign each item to a bin such that number of total used bins is minimized. It may be assumed that all items have weights smaller than b...

2018-09-16 16:02:15 283

原创 [TCP] TCP 40ms Magic Number

待梳理参考文献:http://www.cnblogs.com/wanpengcoder/p/5366156.html https://www.cnblogs.com/wajika/p/6573028.html

2018-09-12 22:52:22 504

原创 [C++] LRU实现

template <typename Key, typename Val>class LRUCache {public: LRUCache(int cache_size_) : cache_size(cache_size_) { }; void put(const int &key, const int &val) { auto i...

2018-09-05 11:12:57 524

原创 [STL] SGI STL红黑树实现的边界条件

背景SGI STL红黑树实现上的特殊点,在于红黑树有一个header辅助节点; - 该header的父节点为root节点; - 其左节点为当前二叉树中的最小值(最左); - 其右节点为当前二叉树中的最大值(最右); - 该节点本身就正好用来当做end迭代器;其初始化代码如下:void init() { header = new Node(); hea...

2018-09-02 14:52:59 258

ECC(bell labs technical journal)

This J›roblem oJ “rloing things right” on a large scale is not essentially new; in a telephone central office, for exa niJ ie, a v ery large numher of operations are performccl iv lii Ie the errors lea‹1iiig to vv roii g numbers are kept well under control, though t I ey have net 1›eeu cont pletely elimiiia te‹I . This has been achieved, in part, through the use ‹if sell-checking circuits. The occasional failure that escapes routine check rug is still ‹letected 1›y' the customer an‹J iv ill, iI it persists, result in customer conipla int, v hile if it is t ransieiit it will J›roduce only occasional iv mug nu nil›crs. .\ I the same t ime the rest of the central ofhce fu nctions sa I isla ct or i I\'. lii a r1i =ita I compu ter, on the other hand, a single failure usual I y me:iris I lie complete la i l ure, in the sense that iI it is detec te‹l no more com J›utiiig can he done until the Jai lure is located ancl correcte‹l , wit i l e if it escapes rlot e‹ ti‹m their it iiival relates all suhsequent operat ions of the machine. Put in other words, in a telephone central office there are ii numlier of J:ara11e1 paths v’1iich are more or less iiiclependent of each other ; in :i digital mach ine there is usually a sinyle ton g path w'hich passes t li ro •b³' 'lie same J, of Sql many time beforethe answer is obtaine‹l.

2014-09-19

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除