# 为什么在许多语言里, String类型都是immutable的?

String做成immutable的意义何在?

# ubuntu下截图

System Settings -> Keyboard -> Shortcuts -> Screenshots

## 可以截全网页的chrome插件

Awesome Screenshot

# 对erlang并行及性能的精彩评论

Almost any language can be parallelized. In some languages it's simple, in others it's a pain in the butt, but it can be done. If you want to run a C++ program across 8000 CPU's in a grid, go ahead! You can do that. It's been done before.

Erlang doesn't do anything that's impossible in other languages. If a single CPU running an Erlang program is less efficient than the same CPU running a C++ program, then two hundred CPU's running Erlang will also be slower than two hundred CPU's running C++.

What Erlang does do is making this kind of parallelism easy to work with. It saves developer time and reduces the chance of bugs.

So I'm going to say no, there is no tipping point at which Erlang's parallelism allows it to outperform another language's numerical number-crunching strength.

Where Erlang scores is in making it easier to scale out and do so correctly. But it can still be done in other languages which are better at number-crunching, if you're willing to spend the extra development time.

And of course, let's not forget the good old point that languages don't have a speed. A sufficiently good Erlang compiler would yield perfectly optimal code. A sufficiently bad C compiler would yield code that runs slower than anything else.

## 参考链接

http://stackoverflow.com/questions/1308527/when-does-erlangs-parallelism-overcome-its-weaknesses-in-numeric-computing

# CLRS

NP完全问题, 这些问题没有最优解, 只能尝试找较好的解

# CSAPP

• 避免由于计算机表示数字的方式引入奇怪的数字错误
• 利用现在处理器和内存的设计优化C代码
• 理解编译器如何实现过程调用,避免缓存溢出带来的安全漏洞
• 写自己的shell,自己的动态存储分配等

# Chapter 1 A Tour of Computer Systems

## 1.3 It Pays to Understand How Compilation Systems Work

Is a switch statement always more efficient than a sequence of if-else statements?
How much overhead is incurred by a function call?
Is a while loop more efficient than a for loop?
Are pointer references more efficient than array indexes?
Why does our loop run so much faster if .we sum into a local variable instead of an argument that is passed by reference?
How can a function run faster when we simply rearrange the parentheses in an arithmetic expression?

what does it mean when the linker reports that it cannot resolve a reference?
What is the difference between a static variable and a.global variable?
What happens if you define two global variables in different C files with the same name?
What is the difference between a static library and a dynamic library?
Why does it matter what order we list libraries on the command line?
And scariest of all, why do some linker-related errors not appear until runtime?

## 1.4 Processors. Read and Interpret Instructions Stored-in Memory

PC: 程序计数器, 是CPU中的一个寄存器, 保存一个内存地址, 这个地址指向下一个要执行的指令

• Store 从寄存器写到内存
• Operate 从两个寄存器取出值, 进行算术运算后覆盖到一个寄存器
• Jump 从指令中取出一个word并覆盖PC的值, 实现跳转

## 1.7 The Operating System Manages the Hardware

1, 保护硬件, 避免应用程序误用导致硬件损坏
2, 提供简单通用的接口供应用程序使用硬件

Kernel virtual memory, 应用程序不允许读写这个区域, 需要调用内核
User stack(created at run time)
Memory-mapped region for shared libraries
Run-time heap(created by malloc)

Unix中一切都是文件统一了不同的IO设备(键盘,鼠标,磁盘,显示器,网络,打印机等)

Amdahl定律

# iostat

## iostat

sudo apt-get install sysstat
yum install sysstat

iostat
Linux 3.19.0-66-generic (chenduo)   2016年08月13日  _x86_64_    (8 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
28.30    0.06   11.32    1.43    0.00   58.88

sda               3.44        21.71        99.34    6225040   28490308


user: 用户级时间比例
nice: nice优先级时间比例
system: 系统级时间比例
iowait: 等待io的时间比例,相当于top里的wa
steal: 虚拟环境下等待物理CPU周期的时间比例
idle: 空闲时间比例, 相当于top里的id

tps: transfer per second, 一次transfer就是一次io

### steal

Xen和KVM支持这个值,貌似vmware和virtualbox都不支持