MSZ006's Cockpit

MSZ006's Blogs

MemoryPool

  • This is a C++ memorypool template class implementation, which is simple to use, convenient and fast. It can replace the original new\malloc, delete\free operations, and also I provide a singleton class memorypool template class implementation
  • This memory pool ensures multi-threaded safety (by locking at the allocate\deallocate), and uses perfect forwarding and variable parameter templates to support the creation of any type of memory pool
  • This memorypool is developed based on the C++11 standard. The code refers to the cacay/MemoryPool, muduo memorypool and boost/memorypool
    Read more »

学习笔记

设计模式

创建模式(5种)

  • 工厂模式:分为简单工厂模式,工厂方法模式,抽象工厂模式
  • 单例模式:确保一个类最多只有一个实例,并提供一个全局访问点,分为预加载和懒加载
    简单的保证预加载时候的线程安全的方法比如synchronized和volatile关键字(JAVA)、双重检查锁定(C++)
  • 生成式模式:当创建一个复杂对象的时候,可以拆分成组件分别进行创造。分为Product(要创建的对象), Builder(定义不同对象的相同创造过程), Director(具体定义对象的创造), ConcreteBuilder(具体不同对象的创造器)四种不同的类
  • 原型模式:本质就是clone,通过复制现有实例来创建新的实例,无需知道相应类的信息
    Read more »

ThreadPool

  • A threadpool implementation based on Round Robin process scheduling algorithm
  • Use features such as std::mutex, std::future, std::foward, std::atomic to ensure multi-threaded safety and perfect forwarding
  • This threadpool is written based on the C++14 standard. The code refers to the Github threadpool open source project and muduo’s threadpool module
    Read more »

python相关

  1. python 转二进制:output = “{0:b}”.format(int_value); bs = “1010” int_value = int(bs, 2) 注意, // 符号是取整
  2. python中,round(4.5)=4, round(4.51)=5, int(4.7)=4, int(4.3)=4,int()可以实现向下取整 7//2=3, 5//2=2
    • 在python中,整数除法是向下取整的,而不是向0取整,比如-3/2 = -2
    • 可以使用int(num1 / float(num2)), 这时int(-3 / float(2)) = -1
      Read more »

C++ 11/14/17/20 笔记

教程链接
https://changkun.de/modern-cpp/zh-cn/00-preface/

C++ 新特性总结

  1. 指针空值: 现在可以使用nullptr赋值给一个空指针,nullptr只可以被隐式转换为指针类型

    1
    2
    3
    int *p = nullptr; //合法
    int n1 = (int)nullptr; //不合法
    int n2 = reinterpret_cast<int>(nullptr); //不合法
  2. nullptr_t 和 nullptr
    nullptr是一个指针空值类型的常量,而nullptr_t是一个指针空值类型,是一个关键字,一个类型

    1
    2
    3
    #include <cstddef>

    std::nullptr_t NullPtr;
    Read more »

算法实用小知识

  • 对于一个数组中出现次数最多的一个数,设数组长度为n,假如这个数出现次数大于$\frac{n}{2}$,那么,num[n/2]一定就是这个数,这个性质也是众数的性质。
    Read more »
0%