1.lua_State : per thread state 相当于一个堆栈,lua执行时放到lua_State上执行,相当于多线程中单个线程

2.global_State: global state, shared by all threads of this state 一个程序实例,相当于一个进程

3. tb->hash[h] = obj2gco(ts)

将TString强转成GCObject 

union GCObject {
GCheader gch;
union TString ts;
}

GCObject *next = p->gch.next 神奇!!!

4. lua_newthread 创建单个lua_State 

lua_newstate 创建lua_State和global_State 类似于 fork、pthread_create和程序启动过程(第一次启动程序时相当于有一个进程一个线程,后面可以创建线程)

5.

#define TValuefields Value value_; int tt_
typedef struct lua_TValue TValue;
#define CommonHeader  GCObject *next; lu_byte tt; lu_byte marked

一共两个tt,用来表示Value的类型,应该是有冗余

6.

/* the following definitions always work, but may be slow */

#if !defined(lua_number2int)
#define lua_number2int(i,n) ((i)=(int)(n))
#endif

一个“简单"的强转也这么有学问!!!!!

7.table

close hashing: 闭散列方法把所有记录直接存储在散列表中。每个记录关键码key有一个由散列函数计算出来的基位置,即h(key)。如果要插入一个关键码,而另一个记录已经占据了R的基位置(发生碰撞),那么就把R存储在表中的其它地址内,由冲突解决策略确定是哪个地址

open hashing:这两种方法的不同之处在于:开散列法把发生冲突的关键码存储在散列表主表之外,而闭散列法把发生冲突的关键码存储在表中另一个槽内


posted on 2012-03-26 10:03  brucexu  阅读(355)  评论(0编辑  收藏  举报