Linux 源码学习 ——offsetof 与 container_of 宏
Linux 内核源码果真精髓,相见恨晚。
offsetof
宏定义如下
1 |
container_of
宏定义如下
1 |
Linux 内核源码果真精髓,相见恨晚。
offsetof
宏定义如下
1 | #define offsetof(type, member) (size_t)&(((type*)0)->member) |
container_of
宏定义如下
1 | #define container_of(ptr, type, member) ({ \ |
What is web container ?
Web container is the component in J2EE which is responsible for handle request from client. Web Server application like tomcat is used to support basic service for web container, e.g., receive request and forward reply to client.
全选
普通模式下, gg
回到文件开始,v
进入可视模式, G
将光标移到文件结束。
复制到系统粘贴板
这个首先要看 vim
是否支持系统粘贴板 vim --version | grep "clipboard"
我这里
clipboard
前是 + 号,表示支持。如果是 -
号,可以百度下方法。
普通模式下,使用 "+y
复制到粘贴板。
交换相邻字符顺序
我编程时有时因为输入太快而导致字符顺序错误。比如将 return 输入成 retrun, endl 输入成 ednl。这样子的话将光标移到出现错误的第一个字符。然后普通模式下 xp
。
正常模式转到插入模式
i
当前光标前插入, I
当前行首a
当前光标后插入, A
当前行尾o
下一行插入, O
上一行插入D
: d$
?
:从下而上查找, /
自上而下查找
保存新文件::w 路径+文件名
:!+bash命令
:运行终端命令
:s/old/new
:将旧的替换成新的,默认为当前行
:3,5s/old/new
:从第 3 行到第 5 行替换
:s/old/new/g
:全局替换
最近读《Effective C++》时读到了 new-handler 一章,了解了 new/delete 一些知识,才知道原来 new/delete 是可以个性化的。
先说简单的一个收获,C++ new 失败后默认后抛出异常,如果我们想让他失败时返回空指针,则应该使用如下写法。
1 | int *pi = new (std::nothrow) int[100000000000L]; |
传送门:Circuit Board
Arsh recently found an old rectangular circuit board that he would like to recycle. The circuit board has R rows and C columns of squares.
Each square of the circuit board has a thickness, measured in millimetres. The square in the r-th row and c-th column has thickness Vr,c. A circuit board is good if in each row, the difference between the thickest square and the least thick square is no greater than K.
Since the original circuit board might not be good, Arsh would like to find a good subcircuit board. A subcircuit board can be obtained by choosing an axis-aligned subrectangle from the original board and taking the squares in that subrectangle. Arsh would like your help in finding the number of squares in the largest good subrectangle of his original board.
Bundle is an animal researcher and needs to go observe K dogs. She lives on a horizontal street marked at metre increments with consecutive numbers 0, 1, 2, 3 and so on. She begins in her home, which is at position 0. There are also N dogs on the street. The i-th dog is Pi metres to the right of her home on the street (multiple dogs can share the same position).
最近转移到了 Ubuntu
系统上,配了一波环境,逐步适应了些 Vim
,虽然一开始觉得没有补全无所谓的,可以练练实力,再安装插件觉得麻烦,但后面还是觉得没有补全少点什么,于是决定还是下个 Vim
补全的插件。大约刻之前在赵老板博客上看到过一个关于 Vim
补全的插件赵老板博文链接,所以打算用那个,也就是 YouCompleteMe
。据说这是 Vim
最难安装的插件?
安装步骤并不算麻烦吧:
Vundle
(Vim
插件管理)Vundle
安装编译 YouCompleteMe
YouCompleteMe
以上几点大家如果没有配置好的话,网上有很多很详细的教程,这里就不细讲了。(完全照抄赵老板博客)
这个网上教程有很多,我就不详述了。我来说下我遇到的一些坑(Win7 + Ubuntu),双显卡(Nvidia + Inter)。大一的时候未能成功,就是因为 Nvidia 的驱动问题。一开始遇到了安装时卡在 logo 界面的问题,Ubuntu 18.04 与前面不同的好像是选择 Try Ubuntu without install
Install Ubuntu
时有了界面。这一下把我搞懵了,因为原来选择的时候按 e
可以编辑 grub
参数,这次不知道去哪里编辑了,尴尬。后面摸索了下发现 F6
有个其他选项,里面有个 nomodeset
,勾选后便解决了这个问题。