[置顶]关于博主

52coder.net是很早之前与同学一起脑洞的域名:中文名可以叫做-我爱程序员。我记得那年冬天孟非主持的非诚勿扰很火,我信誓旦旦的说以后要做一个网站,专门去为程序员解决个人问题,于是就有了现在的这个域名52coder.net。当时比较热衷于论坛,折腾过Discuz,在读书时折腾过,最多的时候同时在线人数超过1000,论坛的注册人数达到了2w左右,现在却早已忘记当初因为什么原因关闭论坛。

博客开始于2017年6月,希望博客用来记录自己的学习过程,渐渐通过几个月的时间喜欢上写点东西,目前学习的内容主要有C语言、数据结构、Linux系统编程、算法、LeetCode等,如果针对文章中的内容有任何疑......

C协程库源码解析

进程vs线程

我们知道,主机上资源有限,一颗 CPU、一块磁盘、一张网卡,如何同时服务上百个请求呢?

多进程模式是最初的解决方案。内核把 CPU 的执行时间切分成许多时间片(timeslice),比如 1 秒钟可以切分为 100 个 10 毫秒的时间片,每个时间片再分发给不同的进程,通常,每个进程需要多个时间片才能完成一个请求。

这样,虽然微观上,比如说就这 10 毫秒时间 CPU 只能执行一个进程,但宏观上 1 秒钟执行了 100 个时间片,于是每个时间片所属进程中的请求也得到了执行,这就实现了请求的并发执行。不过,每个进程的内存空间都是独立的,这样用多进程实现并发就有两个缺点:......

abseil C++ Tips

title abseil C++ Tips

date: 2022-10-28 00:00

url: abseil_cpp_tips

学习abseil C++ Tips

Tip of the Week #1: string_view

当函数参数为(const) string时,常见的一般有3种方法,第三种方法可能不太常见。

// C Convention

void TakesCharStar(const char* s);

// Old Standard C++ convention

void TakesString(const std::string& s);

......

C语言数组初始化的坑

如下代码,输出结果是什么?

#include <stdio.h>

int main()

{

int arr[10] = {10};

for(int i = 0;i < 10;i++)

printf("%d\n",arr[i]);

return 0;

}

输出结果:

10

0

0

0

0

0

0

0

0

0

本来以为应该全部输出的是10。

看到介绍:https://en.cppreference.com/w/c/language/array_initialization

文中有几个例子,引以为戒:

int x[] = {1,2,3}; //......

网络编程中的SIGPIPE信号

在极客时间中学习专栏<网络编程实战>中有一个思考题,觉得下面的评论回答的有点浅显,结合工作中排查过的实际问题,想结合自己的理解展开讲下。

源代码(client.c):

#include <stdio.h>

#include <error.h>

#include <stdlib.h>

#include <sys/socket.h>

#include <unistd.h>

#include <errno.h>

#include <string.h>

#include <sys/socket......

日常开发笔记总结(十三)

向Linux登录终端发消息

同一台服务器,可能有很多个用户登录在上面,每个用户都是一个系统终端,可以向其他终端发送消息,同在服务器上开发的开发人员可以简单的互动(不能回复)一下哈!

一,效果

先登录一个终端,如下:

[root@localhost /]# who

root tty1 2013-02-16 18:14 (:0)

root pts/0 2013-02-17 02:01 (:0.0)

[root@localhost /]#

登录的终端为pts/0。然后再打开一个终端,如下:

[root@localhost ......

日常开发笔记总结(十二)

可以直接在命令行中定义函数,通过使用declare命令来打印出来,使用shell函数,只需要在命令行中输入函数名称。一旦不再需要某个shell函数,可以使用unset命令来删除它。

[root cplusplus]#foo() { echo "Inside function"; }

[root cplusplus]#foo

Inside function

[root cplusplus]#declare -f foo

foo ()

{

echo "Inside function"

}

[root cplusplus]#unset foo

[root cplusplus]#declare ......

[LeetCode C++实现]101. Symmetric Tree

好久没刷题今天有时间挑选了这道Symmetric Tree(对称二叉树)。

按照最直观的思路层序遍历,然后判断每一层是否对称。

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode() : val(0), left(nullptr), right(nullptr) {}

* TreeNode(int x) : val(x), left(nullptr), righ......

日常开发笔记总结(十一)

git命令使用

新工作中由于是在linux环境上写代码,因此原来使用小乌龟提交代码的方式不再适用,因此利用空余时间学习git命令行的使用。

命令行向github推送代码,先在github上创建了仓库:

echo "#hello,world" >> README.md

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin git@github.com:52coder/hello-world.git

git push -u origin ......

google benchmark学习与使用

google benchmark

#include <benchmark/benchmark.h>

#include <array>

constexpr int len = 6;

// constexpr function具有inline属性,你应该把它放在头文件中

constexpr auto my_pow(const int i)

{

return i * i;

}

// 使用operator[]读取元素,依次存入1-6的平方

static void bench_array_operator(benchmark::State& state)

{

......