07 2012 档案

understanding assembly code (2)
摘要:What is this topic about?It is a study on the difference betweeen a function returning a vector and a function accepting a reference to a vector as a parameter.[torstan]$ more vec.cc#include<vector>using namespace std;vector<int> f(){ vector<int> v; v.push_back(2); return v;}/*g++ 阅读全文

posted @ 2012-07-23 19:21 Torstan 阅读(434) 评论(0) 推荐(0)

understanding assembly code (1)
摘要:1) BackgroundSometimes, when we meet with a problem very hard to explain or understand, we can try more powerful tools, e.g. math or assembly code. In... 阅读全文

posted @ 2012-07-22 21:18 Torstan 阅读(572) 评论(0) 推荐(0)

study on source code of Tcmalloc
摘要:This night, I downloaded the source code of Tcmalloc after supper, and studied it for several hours. I am recording some findings here in case that I forget them tommorow.1. File libc_override_gcc_and_weak.h does override malloc routines (malloc, free, realloc, and so on) on systems that define the 阅读全文

posted @ 2012-07-19 20:37 Torstan 阅读(408) 评论(0) 推荐(0)

exercises on recursive definition of set
摘要:Q1. give a recursive definition for the set of ordered pair of positive intergers, S={(a, b)| a, b are positive intergers, and a|b}Answer:basis step: (1, 1) belongs to S;recursive step: if (a, b)belongs to S, (a, a+b) belongs to S, and (a+1, a+1) belongs to S. 阅读全文

posted @ 2012-07-15 12:13 Torstan 阅读(160) 评论(0) 推荐(0)

a fast algorithm to compute the area of a polygon
摘要:Assume there is a polygon (v1, v2,...vn), where vi, (1<=i<=n) are its vertices. What is the area of this polygon?We have learnt cross product, which can be used to calculate the area of a triangle. We can also use this to calculate the area of a polygon by dividing the polygon with n segments 阅读全文

posted @ 2012-07-07 13:15 Torstan 阅读(287) 评论(0) 推荐(0)

customize your own memory allocator (2)
摘要:I have made a more sophisticated version ofmemory allocator based on mmap. It can avoid memory increacement issue happened in traditional memory allocator, e.g. glibc malloc/free. However, it has two disadvantages. One of them is that this allocator is slower than glibc malloc/free since it call mma 阅读全文

posted @ 2012-07-06 20:56 Torstan 阅读(226) 评论(0) 推荐(0)

智力题2
摘要:有一道样的题:三个杯子,一个13L,装了10L水;一个7L,装了2L水;一个6L,装了3L水,问怎样倒,使得3个杯子各有5L水。没有其它任何工具,杯子上没有刻度,不能倒出1/2,1/3之类的。请问怎么倒? 如果不能做到,请证明。解答:不能做到。[引理]从A杯子倒水到B杯子,只能把A里面的水全部倒完,或者把B杯子倒满。[证明]假设能做到,最后一步是这样的:有一个杯子A装了5升,另外一个杯子B有一些水,还剩一个杯子C有一些水,假设从B倒水到C,使得B和C都有5升水。另一方面,从B倒水到C只有两种方式,把B倒空,或者把C倒满。第一种方式,把B倒空,显然做不到每个杯子5升水,因为B剩下0升,且这是最后 阅读全文

posted @ 2012-07-04 11:13 Torstan 阅读(263) 评论(0) 推荐(0)

导航