C++ Tips #3: 字符串连接
翻译自Tip of the Week #3: String Concatenation and operator+ vs. StrCat()
本文主题是字符串连接,string::operator+和absl::StrCat()我们经常听到有人说使用操作符(+)连接字符串不...
C++ Tips #1: string_view
翻译自:Tip of the Week #1: string_view,如有错误欢迎指正。这个tip的背景是,将字符串作为函数参数进行传递。常规方法将字符串作为函数参数进行传递,容易想到的是以下两个方法:void TakesCharStar(const char* s); ...
将不同类型的对象放进同一个容器
目标:不同类型的对象,放进同一个容器。(下文以数组表示容器)代理类问题:现有不同种类的交通工具类派生层次,如下:class Vehicle {
public:
virtual double weight() const = 0;
virtual ...
C++11 中的 delete 使用场景
C++11 中引入的 delete 描述符主要有如下两个使用场景:禁止编译器自动生成拷贝Effective C++ 中提到通过“私有化 + 只声明、不定义” 的方法禁止编译器生成某些拷贝构造函数、拷贝操作符等。在C++11及以后,可以通过 delete 描述符来实现。cla...
madvise()
The madvise() system call allows applications to tell the kernel how it expects to use some mapped or shared memory pages, so that the ke...
浅谈设计模式——装饰者模式(未完成)
装饰者模式可以动态地将责任附加到对象上,若上扩展功能,装饰者提供了比继承更有弹性的替代方案。装饰者模式的重要核心部件Component(抽象构件)具体构件和抽象装饰类的共同父类,声明了在具体构件中实现的业务方法,它的引入可以使客户端以一致的方式处理未被装饰的对象以及装饰之后...
线性哈希
线性哈希是一种动态扩展哈希表的方法,其“线性”的名字源于这种方法每次只扩展一个Bucket的容量。这种方法需要两个哈希函数。At any given point of time, this method works with at most two hashing func...
mmap() will be called by malloc()?
In the man page of malloc, there(NOTES section) is a paragraph as follows:Normally, malloc() allocates memory from the heap, and adjusts ...
The qualifier explicit for constructors callable with one argument
This article explains when we should use the qualifier explicit and when we shouldn't.Avoids undesirable conversionsNormally, if a constr...
Keyword restrict in C99
While reading Advanced Programming in the UNIX Environment, I noticed this:#include
FILE* fmemopen(void *restrict buf, size_t size, cons...