`nmcnt`和`type`的R的`sxpinfo`标题

时间:2017-07-24 09:20:41

标签: c r struct internals

R的internals手册的第1.1.2节说明了

  

`sxpinfo'标头定义为下面的64位C结构:

 struct sxpinfo_struct {
     /* Type and namedcnt in first byte */
     unsigned int nmcnt : 3;   /* count of "names" referring to object */
     unsigned int type : 5;    /* discussed above */
     /* Garbage collector stuff - keep in one byte to maybe speed up access */
     unsigned int gccls : 3;   /* node class for garbage collector */
     unsigned int gcgen : 1;   /* old generation number - may be best first */
     unsigned int mark : 1;    /* marks object as in use in garbage collector */
     /* Object flag */
     unsigned int obj : 1;     /* set if this is an S3 or S4 object */
     /* Flags to synchronize with helper threads */
     unsigned int in_use: 1;   /* whether contents may be in use by a helper */
     unsigned int being_computed : 1;  /* whether helper may be computing this */
     /* "general purpose" field, used for miscellaneous purposes */
     unsigned int gp : 16;     /* The "general purpose" field */
     union {
       struct {                /* field below is for vectors only */
         R_len_t truelength;   /* for old stuff - may someday be defunct... */
       } vec;
       struct {                /* fields below are for non-vectors only */
         /* Debugging */
         unsigned int debug : 1;  /* function/environment is being debugged */
         unsigned int rstep : 1;  /* function is to be debugged, but only once */
         unsigned int trace : 1;  /* function is being traced */
         /* Symbol binding */
         unsigned int basec : 1;       /* sym has base binding in global cache */
         unsigned int spec_sym : 1;    /* this is a "special" symbol */
         unsigned int no_spec_sym : 1; /* environment has no special symbols */
         unsigned int unused : 2; /* not yet used */
         /* Primitive operations */
         unsigned char var1, var2;/* variants for evals of fast primitive args */
         unsigned char pending_ok;/* whether args can have computation pending */
       } nonvec;                  /*  - only one bit, but maybe faster as byte */
     } u;
 };

这给我留下了两个问题,关于nmcnttype字段(第一个字节):

  1. 为什么25-2 SEXPTYPEs 5 位代表2 when = 64?25?
  2. 是否有2³= 8个名称的限制可以引用给定的(例如S4)对象?
  3. 提前致谢。

0 个答案:

没有答案