Marstone Studio

洗碗与倒垃圾

Posted on: 2009/08/10

今天发现,洗碗与倒垃圾具有惊人的相同点。

早晨超哥下楼顺便把垃圾带下去了,我便拿了个新垃圾袋。
这时突然想到,我是否要现在换呢?突然领悟到,在第一次扔垃圾的时候换即可。

因为不管是谁,每次扔垃圾,都会检查一下垃圾袋是否为null,如果为null,则new一个。
突然联想到在青岛的日子,一直没想明白的问题,是饭后洗碗;还是饭前洗碗。
事实证明,吃的时候洗和吃过之后洗,性能上差别不大。

这个模式,有两个类似的利用。
第一个是数据库的惰性加载(Lazy Load)。
几乎所有的数据库,都是惰性的。这对程序的性能有很好的提升。
原因很显然,很多数据,可能根本不需要加载。
不过垃圾袋和洗碗却几乎都是必要的,程序空闲时即可创建这个对象。

第二个问题是数据的同步。
这个也是惰性的,但是差别是,不管数据有多脏,同步一次即可。
这就好比,自己的碗如果不是很脏可以一直不刷…
这貌似在历史上也发生过不止一次哈。

Leave a comment


  • None
  • Ara: After time high in exciting we can fall asleep in another of over than three thousand hotel rooms.
  • marstone: hi sam you would probably notice that project was forked from other repos. i almost did nothing on it. afaik ingress started to use an encryption alg
  • Sam: Heya, i saw your ingress for ios on github. would you be able to make a pokemon go app for ios 7? it is in great demand since alot of people have ios

Categories