lua-users home
lua-l archive

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


On Fri, Apr 11, 2014 at 7:47 PM, Tim Hill <drtimhill@gmail.com> wrote:

On Apr 9, 2014, at 1:10 AM, Rena <hyperhacker@gmail.com> wrote:



The code path I'm imagining is:

-receiveMessage()
-find the next message in the queue
-set a flag saying "we're receiving a message of length n"
-lua_pushlstring(L, msg, n);
-the allocator sees the flag is set, sees Lua asking for a string of length n, and gives it the message's memory block (with refcount set appropriately)
-receiveMessage() returns

But I wonder if it's possible that for whatever internal reasons, Lua happens to allocate an unrelated string as well during this time, also of length n?

If not then this would definitely be an interesting solution.

--
Sent from my Game Boy.

For the very reason you stated I think this is a fragile solution. You have no guarantee that Lua will directly call your allocator for the string push .. all sorts of other things could happen, and indeed change from release to release of Lua. It could intern the string. it could re-use an internal buffer cache. It could allocate some OTHER string internally before allocating space for your string.

—Tim


I don't think interning strings or reusing existing ones would cause an issue. But unfortunately I think the other issues make this solution unworkable. Shame, I rather liked it.

--
Sent from my Game Boy.