lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

What a pain.

I did a test to see if I could get strings to behave like atoms. I tried a short, 3 char string and a long, 35 char string. From the code it looks like strings above and below 32 chars are handled differently. I assume that is what everyone here has been talking about when saying "short strings".

I did 3 tests. I loaded the strings, got back their char* pointers, then put them into the registry and popped them. Then I forced a GC and loaded the strings in the registry onto the stack and checked their addresses. They matched. Then I loaded those same strings again with new pushstring() calls, and they matched. Then I executed these two functions, in turn:

function _getabc()
    return "abc"
function _getlongString()
    return "AVeryVeryVeryVeryVeryVeryLongString"

Looking at the returned string values, the first one matched and the second one didn't.

That means that, at best, I would be able to cache only short strings. That might not be too bad. But I wish there were a way to guarantee that AT LEAST any string under 32 characters can be cached in this way. It seems like Lua internally uses this characteristic of short strings. So it seems like this should be a reasonable guarantee to bring out to the C interface. Any idea if this will be done in the future?

chris marrin                ,""$, b`    $                             ,,.
(408) 955-3049          mP     b'                            , 1$'
Sony    ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'