Wednesday, February 27, 2013

Markdown 笔记

Markdown cheat sheet

Sunday, February 24, 2013

[C++] 小探iterator

#include <iostream>
#include <map>

using namespace std;

main() {
    map<int int> a;
    map<int int>::const_iterator cit;
    map<int int>::iterator it;
    a[1] = 15;
    printf("&a[1] = %p a[1] = %d\n", &a[1], a[1]);
    cit = a.find(1);
    it = a.find(1);
    it->second = 255;
    printf("%lx %p %d\n", *((long*) &it), &(it->second), it->second);
    printf("%lx %p %d\n", *((long*) &cit), &(cit->second), cit->second);
}
运行结果:
$ ./a.out
&a[1] = 0x7fb58a403954 a[1] = 15
&it =0x7fff520aa898 it =7fb58a403930 &(it->second) =0x7fb58a403954 it->second =255
&cit=0x7fff520aa8a0 cit=7fb58a403930 &(cit->second)=0x7fb58a403954 cit->second=255
几个结论:
  • 从cit只占用8个字节大小来看(&it-&cit), map::const_iterator 或者map::iterator, 其实内容就是一个8-byte的指针
  • 从cit和it都存着同样内容(0x7fff520aa898)来看, 内容其实就是map中该元素的地址.
  • 而且iterator的first 和second并不是值拷贝. 比如我们使用it对a[1]的值更新后, const_iterator只是该iterator不能对map做改动而已.

Thursday, February 21, 2013

[Emacs] Doxymacs


C-c d ? will look up documentation for the symbol under the point.
C-c d r will rescan your Doxygen tags file.
C-c d f will insert a Doxygen comment for the next function.
C-c d i will insert a Doxygen comment for the current file.
C-c d ; will insert a Doxygen comment for the current member.
C-c d m will insert a blank multiline Doxygen comment.
C-c d s will insert a blank singleline Doxygen comment.
C-c d @ will insert grouping comments around the current region.

Sunday, February 17, 2013

[Golang] Golang笔记贴(坑)

啥是Go?

Go是Google在09年左右新推出的一门语言.在语法上说, Go有点类似于C.但是Go的特性在于其高并发性和事件处理,使得它特别适合作为分布式编程的语言.CMU的15-440(distributed systems)开始使用Go做教学语言, 结果效果出奇的好.

安装设置Go

Go的安装 $GOPATH, $GOROOT

如果GOPATH=/path/to/A:/path/to/B, 那么go在找库的时候就从/path/to/A/pkg, /path/to/B/pkg这样的顺序.
安装远端repository里的库

Reference

Go语言简介(上):语法
Go语言简介(下):特性

Saturday, February 16, 2013

[Linux] Linux上NUMA相关的命令

查看NUMA的memory设置等

$ cat /sys/devices/system/node/node*/meminfo 
Node 0 MemTotal:       16777216 kB
Node 0 MemFree:           14312 kB
Node 0 MemUsed:        16762904 kB
...
Node 0 HugePages_Total:  1000
Node 0 HugePages_Free:    744
Node 0 HugePages_Surp:      0
Node 1 MemTotal:       16763940 kB
Node 1 MemFree:         5289568 kB
Node 1 MemUsed:        11474372 kB
...
Node 1 HugePages_Total:  1000
Node 1 HugePages_Free:   1000
Node 1 HugePages_Surp:      0

查看NUMA统计数据

比如多少local node reference, 多少foreign node reference
$ cat /sys/devices/system/node/node*/numastat
numa_hit 759046092
numa_miss 333483705
numa_foreign 236930883
interleave_hit 12690
local_node 746065583
other_node 346464214
numa_hit 506048971
numa_miss 236930883
numa_foreign 333483705
interleave_hit 12713
local_node 507619074
other_node 235360780

使用numactl设置task的numa属性

prefer(并非强制)使用numa node0来执行my_app
$ numactl --preferred=0 ./my_app arg1 arg2
强制使用numa node0 的local cpu和local memory来执行my_app
$ numactl --cpubind=0 --membind=0 ./my_app arg1 arg2

Saturday, February 02, 2013

[Latex] 编辑文档的tips

watermark

有时候我们需要在每一页打上一个水印, 这时候可以使用draftwatermark这个package.
\usepackage{draftwatermark}
\SetWatermarkText{this is a draft}
\SetWatermarkScale{0.5}
更多的参数可见 http://texblog.org/tag/draftwatermark/还有一个叫draftcopy的package也是可以做类似的事情, 但是似乎在我这里有问题