Showing posts with label coder. Show all posts
Showing posts with label coder. Show all posts

2007-05-05

下面这段python代码会吃掉你的所有内存,是时候抛弃python-numeric了


import Numeric
import numpy
a = Numeric.zeros([1, 1])
while True:
a[0, 0] = numpy.int32(0)

2007-02-11

a trap I met today

the following code:


vector<int> a;
// init a
for(int i = 0; i < a.size()-1; i+=2) {
// do something;
}


will crash if a is empty, because a.size() return a size_t, which is unsigned, then a.size()-1 is a very large unsigned value. it should be changed to:


vector<int> a;
// init a
for(int i = 0; i+1 < a.size(); i+=2) {
// do something;
}


P.S. I does not consider a.size() > 2G, at least it will not happen in this program.

2007-02-09

topcoder yellow!

第15轮,终于变黄了,不容易啊。

http://www.topcoder.com/tc?module=MemberProfile&cr=20557476