Cnangel: July 2009的归档

我们知道在一个结构体当中,往往为了节省内存空间,会花点心思进行字节对齐。
typedef struct __aligning
{
      unsigned short n;
      unsigned int m;
      unsigned short x;
} aligning1;
针对上面的struct:aligning1,我们使用sizeof计算会得到12个字节,显然没有符合4字节对齐的方式,以下写法更为科学:
typedef struct __aligning
{
      unsigned short n;
      unsigned short x;
      unsigned int m;
} aligning2;
此时struct会占用8个字节。

然而往往为了更细化,可使用bool(c++)或者enum获得更小的容器来节省空间,但是1个字节已经成为下限,如果有8个成员变量,取值范围是1和0的话,也需要8个字节,如果节省更多的空间呢?
C经典语法类型,表示bit方式可以如下:
typedef struct __aligning
{
      unsigned n:1;
      unsigned m:1;
      ...
      unsigned t:1;
} aligning3;
这样最多也就4个字节,其实4个字节可以最多表示32个成员变量,每个变量1bit;
再结合实际情况,用实际的最大值,结合字节对齐,就可以节省更多的内存空间,大家在工程中不妨试试哟!

白话搜索引擎

| 暂无评论

    在五六十年代,谁拥有了原子弹,谁就是一个超级大国,在国际上也会受到其他国家的尊敬,如今的时代,谁拥有了搜索引擎,谁就拥有了在互联网的重型武器。

   搜索引擎并不是每个公司都有的技术,搜索引擎的海量存储和海量的计算能力非任何一家公司所能及,即使在中国著名的阿里巴巴、腾讯等公司也不例外。在独立开发的搜索引擎技术方面,百度、新浪、搜狐以及原来的3721(已被中国雅虎收购)等公司都做过实验性工作,但是存活下来的全网搜索引擎只剩下百度一家。目前Google中国和中国雅虎仍然使用的是非独立开发的搜索引擎技术,是借用美国的技术的衍生。

 

    Perhaps you rarely face it, but once you do, you surely know what's wrong: lack of free memory, or Out of Memory (OOM). The results are typical: you can no longer allocate more memory and the kernel kills a task (usually the current running one). Heavy swapping usually accompanies this situation, so both screen and disk activity reflect this.

    At the bottom of this problem lie other questions: how much memory do you want to allocate? How much does the operating system (OS) allocate for you? The basic reason of OOM is simple: you've asked for more than the available virtual memory space. I say "virtual" because RAM isn't the only place counted as free memory; any swap areas apply.

html2wiki

| 暂无评论

保留颜色语法高亮是最重要的。要不vim的html输出就没意义了。

先建立一个html2wiki.sed

s/<a href=”/[[/g
s/" mce_href="/[[/g
s/">http/|http/g
s/</a>/]]/g

s/<font |</font>/@@/g
s/color=”/color(/g
s/”>/):/g

/<pre>|</pre>/ d
/<body|</body>/ d
/<html>|</html>/ d
/<head>|</head>/ d
/<meta/ d

s/<title>/!!/g
s/</title>//g

s///// //g
s/<b>|</b>|<B>|</B>/”/g
#&><”
s/t/>/g
#s/^ */>/g
s/ {8}/>/g


然后,建立一个bash文件html2wiki.sh:

$ cat ./html2wiki.sh
#!/bin/bash

vim -c ":syntax on|:colorscheme morning|:TOhtml" -c ":w|:qa" $1

file $1.html|grep HTML
[ $? != 0 ] && exit;
sed -f ./html2wiki.sed $1.html > $1.wiki


直接这样运行。
$ html2wiki.sh 4428.c

得到的wiki文件,可以直接粘贴到tiddlywiki的编辑里面即可。

关于此归档

这里是CnangelJuly 2009发表的所有日记。

上一篇日记Cnangel: June 2009

下一篇日记Cnangel: August 2009

主索引归档页可以看到最新的日记和所有日记。

August 2012

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Powered by Movable Type 5.14-en