xcb 获取鼠标指针的坐标

1typedef struct xcb_query_pointer_reply_t {
2    uint8_t      response_type;
3    uint8_t      same_screen;
4    uint16_t     sequence;
5    uint32_t     length;
6    xcb_window_t root;
7    xcb_window_t child;
查看全文

显示 X11 的空闲时间

1// gcc main.c -lX11 -lXss
2#include <stdio.h>
3#include <X11/extensions/scrnsaver.h>
4
5int main(void) 
6{
7    Display* dpy = XOpenDisplay(NULL);
查看全文

Linux CUDA 驱动失效问题的解决办法

在使用 Linux 的时候,如果经常进行升级,时不时会遇到驱动失效的问题:

1$ nvidia-smi 
2NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. 
3Make sure that the latest NVIDIA driver is installed and running.
查看全文

NVIDIA驱动安装成功但无法使用

现象

1$ nvidia-smi
2NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
3
4$ dkms status
5nvidia, 470.86, 5.13.0-22-generic, x86_64: installed
查看全文
查看全文
查看全文
查看全文

SIMD 示例

所谓 SIMD 就是一次指令计算多个数据,例如 AVX256 一次计算 256 位数据。

  • int 是 32 位,所以 AVX256 一次计算 8 个
  • double 是 64 位,所以一次计算 4 个

以计算 double 加法为例:

1__m256d m256x; // 定义标识 AVX 寄存器的变量
2__m256d m256y;
查看全文

C++ 函数消抖

函数消抖 指在短时间内连续多次调用同一函数,仅最后一次调用生效。

形如:

1auto debouncedFn = debounce(fn, 100);

通常将需要消抖的函数封装成一个新的函数,新的函数进行延迟后调用原函数:

查看全文

C++ 容器内元素重复析构的问题

说明

std::vector 这种连续空间的容器,当空间不足时需要整体重新分配内存,并将旧的数据迁移过去。 首先会使用 std::move_if_noexcept 尝试进行移动。 因此如果元素类型的移动构造函数没有标明 noexcept 则不会被调用。 之后会通过 std::uninitialized_copy 尝试进行拷贝。

这是因为移动中如果产生异常,部分源数据已经被移动,将无法恢复原状。而拷贝中如果发生异常,源数据不应改变,只要返回失败即可。

查看全文