- 博客(45)
- 资源 (5)
- 收藏
- 关注
原创 C++11 std::async 结合 lambda, std::function<>的例子
std::async std::function lambda
2022-08-12 23:49:46 865
原创 malloc和new之间的不同-实战篇
很多人在面试时都会被问malloc和new之间的不同,有些人会说一下。但很多人可能并没有真正的遇到过因其不同而带来的问题。1 new会调用构造函数,malloc不会。这句话的真正意思是,new会给struct的成员分配空间,而malloc其实则不一定。struct Data { string name; int id;};struct Data* pData = (Data*) malloc(sizeof(Data));if (pData == nullptr) {
2022-05-17 16:14:24 133
原创 如何管理大量的定时任务
目前知道的常用方法是【Hashed Wheel Timer】该实现是依据是George Varghese和Tony Lauck在1996年的论文。论文附件PPT附件
2022-05-17 16:08:58 329
原创 System Design的相关准备材料
整理了一些材料,后续会继续补充。有需要补充的也可以在留言中说下,谢谢。Grokking the System Designaws solutions architect certificate《design data intensive application》《micro services patterns》《guide to reliable distributed systems》《System Design Interview》作者 Alex XuHigh Scala
2022-04-17 11:28:16 191
原创 游戏AI算法相关文章合集
在AI寻路决策中运用势力图(Influence Map) – AI分享站行为树(Behavior Tree)实践(1)– 基本概念 – AI分享站游戏角色并行状态机之boost::msm_senlin2684的博客-CSDN博客FSM(状态机)、HFSM(分层状态机)、BT(行为树)的区别_小鱼儿飞呀飞的博客-CSDN博客游戏服务器总纲_bestans的博客-CSDN博客帧锁定同步算法 - Skywind Inside体育竞技游戏的团队AI - Skywind Ins.
2022-03-27 09:48:42 4185
原创 C++中如何在一个类中初始化其它类
#include <iostream>using namespace std;class GPU {public: GPU(int id) : m_gpuId(id) { cout << "GPU" << endl; }private: int m_gpuId;};class Memory {public: Memory(int mem) : m_memSize(mem) { .
2022-01-27 21:34:53 2400
原创 现代C++中如何检测new的失败
C++和C,在分配动态内存时,分别用new和malloc,但检查其结果的方式完全不同。在C中,一般是检查返回指针是否为NULL,但这在C++中可能行不通。#include <iostream>using namespace std;struct GPU { string m_name; uint64_t m_serialNumber;};int main(){ struct GPU* pGpu = nullptr; try {
2022-01-27 21:04:26 1151
原创 谈谈为何需要将类的成员函数声明为private
1 析构函数声明为私有, 有些资源必须要在析构前释放掉,则将析构函数声明为私有,然后另外再定义一个公有的destroy函数,先做释放资源操作,再调用析构函数。 delete this.2 当类成员中有文件描述符,锁之类的系统资源时,因为这些资源不具备可复制性。所以要防止使用者复制使用它们。此时的做法是将copy构造函数、赋值操作符声明为private3 析构函数声明为私有,则在创建该类的对象时必须是在堆上创建,如果是在栈上创建会导致编译不过。#include <iostream>
2022-01-26 18:03:59 884
原创 socket编程二:使用select
tcp_server.c#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <sys/socket.h>#include <sys/types.h>#include <sys/select.h>#include <sys/time.h>#include <netinet/in.h>#include <arpa
2022-01-18 17:42:15 282
原创 socket编程一:使用fork()实现最基础的并发模式
tcp_server.c#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <unistd.h>#include <netinet/in.h>#include <arpa/inet.h>int main(int argc, char **argv){ // crea
2022-01-17 15:30:26 499
原创 使用C++11 可变参数模板计算
#include <iostream>using namespace std;template<typename T>T Calculate(T t){ return t;}template<typename T, typename ... Args>T Calculate(T first, Args... rest){ return first * (1 << sizeof...(rest)) + Calculate&.
2021-12-18 17:37:41 609
原创 回调使用lambda
// lambda_callable.cpp#include <iostream>using namespace std;template <typename T, typename Func>void ForEach(T* begin, T* end, const Func& func){ while (begin != end) { func(*begin++); }}int main(int argc, char .
2021-12-07 20:53:34 507
原创 operator() 用法之一
#include <iostream>using namespace std;template <typename T>struct Print { void operator() (const T& msg) const { cout << msg << " "; }};template <typename T, typename Func>void ForEach(T* beg.
2021-12-07 20:44:09 180
原创 重载operator()
#include <iostream>using namespace std;class A {public: A(string msg) : m_msg(msg) { cout << "A constructor:" << msg << endl; } virtual ~A() { cout << "A destructor" << endl; .
2021-12-07 20:33:28 191
原创 类模板中的成员函数能否声明为虚函数
#include <iostream>using namespace std;template<typename T>class A {public: A(T a):m_a(a) { cout << "A::a" << endl; } virtual void b(T bb) { cout << "A::b" << endl; }priva.
2021-12-06 18:49:01 168
原创 虚函数能否声明为内联
#include <iostream>using namespace std;class A { public: virtual inline void a() { cout << "A::a" << endl; }; inline virtual void b() { cout << "A::b" << endl; }};int main().
2021-12-06 18:44:58 62
原创 子类成员直接调用父类的函数
#include <iostream>using namespace std;class A {public: virtual void a() { cout << "A::a" <<endl; }};class B : public A {public: virtual void a() { cout << "B::b" << endl; A *aa = .
2021-12-06 18:42:06 499
原创 deque用法测试
#include <deque>#include <iostream>using namespace std;class Event {public: Event(int type, string data) : m_eventType(type), m_eventData(data) { cout << "construct Event:" << m_eventType << ", " <&l.
2021-11-16 11:27:04 599
原创 emplace_back与push_back的真实效率比较
我测下的结果,反而是push_back耗时更小些。这个明显和大家的结论不一致。#include <vector>#include <iostream>#include <sys/time.h>using namespace std;int64_t GetSysTimeMicros(){ timeval tv; gettimeofday(&tv, 0); return (int64_t)tv.tv_sec * 100000
2021-11-10 20:33:43 530 2
原创 centos6.8上编译安装PHP7.4.12时遇到的问题解决思路
每个人的环境不同这里不穷举所有的例子,此处仅分享解决问题的思路。1 configure时遇到sqlite3 onig等库确实,使用yum install安装后重新configure,如过提示还是无法找到,仔细看提示。根据提示设置环境变量即可。#how to fix the oniguruma dependency issueexport ONIG_CFLAGS="/usr/bin/onig-config"export ONIG_LIBS="/usr/lib64/"2 make时遇到u.
2020-11-13 23:58:27 1083
原创 用文件夹的方式去导入之前chrome浏览器器收藏夹内容
先关闭chrome浏览器X:\Users\你的用户名\AppData\Local\Google\Chrome\User Data\Default\找到\databasesBookmarksBookmarks.bak拷贝到你现在的C盘C:\Users\你的用户名\AppData\Local\Google\Chrome\User Data\Default\打开chrome浏览器...
2020-11-05 23:54:58 562
转载 wordpress中解决页面未找到的问题
1 在根目录下新建.htaccess2 写入如下配置# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule
2020-10-15 21:39:55 2025
v4l(video4Linux)
2008-07-30
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人