From: <lm...@bi...> - 2009-05-07 15:12:51
|
BTW, we implemented NULL in our fork of the tcl tree trivially. Contrary to all the discussion here, we don't really care if there is a string rep for NULL, we just wanted a way to have an out of band indicator that the value of the variable was undefined or null, whatever you want to call it. I noticed that the ref count for tcl objects is a 32 bit signed quantity, so the most references you could have to an object was 2 billion. I made it an unsigned 31 bit quantity and used the high bit to mean the object is undefined. We used an empty string as the object's value but that's neither here nor there, we don't look at it, we added a [defined] proc that just returns the bit. Tcl can shimmer it all it wants, we don't care. Works great for us and seems to fit into the tcl code reasonably well. I point it out because if you think about it a bit, it's pretty darned unlikely that you need anything like 31 bits for reference counting. I bet that you could use 16 and be fine. I'm sure Colin will disagree just to disagree, but seems to me that you could steal several bits from the top of the ref count and do the TCL_MEM_DEBUG the same way we did undef instead of making it a negative. ==== generic/tcl.h ==== 2009-03-24 05:54:41-07:00, ro...@wo... +10 -1 Add undef field to the Tcl_Obj structure to indicate whether the object is the L undefined value. --- 1.231/generic/tcl.h 2009-02-13 11:29:39 -08:00 +++ 1.232/generic/tcl.h 2009-03-24 05:54:41 -07:00 @@ -763,7 +763,16 @@ typedef struct Tcl_ObjType { */ typedef struct Tcl_Obj { - int refCount; /* When 0 the object will be freed. */ +#ifndef TCL_MEM_DEBUG + int refCount:31; /* When 0 the object will be freed. */ + int undef:1; /* Used by L to mark an object as having + * the undef value. Steal a bit from + * refCount to avoid increasing the + * Tcl_Obj memory footprint. */ +#else + int refCount; + int undef; +#endif char *bytes; /* This points to the first byte of the * object's string representation. The array * must be followed by a null byte (i.e., at -- --- Larry McVoy lm at bitmover.com http://www.bitkeeper.com |