[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: xstring 1.0.1 - fast external strings for embedded Lua
- From: Chip Salzenberg <chip@...>
- Date: Tue, 15 Jul 2008 11:23:16 -0700
The module I presented at the Lua Workshop 08, now with MIT License:
This Lua module provides the abstraction "xstring", or "external string".
An external string is a userdata object that represents a string (more
generally, a memory area) not owned by any Lua instance. It solves the
problem of performance loss and memory usage caused by Lua's taking an
internal copy of all strings before working with them.
The xstring implementation is based on two C structures: the xsbuf and the
xstr. An xsbuf is a structure with a reference count, a pointer, and a
size. An xstr is the structure inside the userdata of the Lua xstring
objects, which refers to a portion of an xsbuf.
The xsbuf and xstr structures are both quite small and simple; it is
therefore extremely inexpensive to create and destroy them. Their only
complexity is actually an efficiency hack: each xstr actually represents a
*substring* of a given memory area (usually, however, this is the substring
of the whole). This allows for sub-xstring creation without forcing
conversion to an interned Lua string.
Share & Enjoy!
Chip Salzenberg <email@example.com>