[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: zero-copy read() into Lua string?
- From: Miles Bader <miles@...>
- Date: Mon, 10 Jan 2011 13:02:04 +0900
Josh Haberman <firstname.lastname@example.org> writes:
> char *lua_pushwstring(lua_State *L, size_t len);
> void lua_finalizewstring(lua_State *L);
> (lua_finalizewstring() is there in case Lua wants to internally
> precompute a hash of the string or anything like that.)
> In some cases (like read()/fread()) this could save a memory copy for
> string data that is flowing from C->Lua, which seems like a big
> benefit. Though I haven't implemented this idea to perform benchmarks,
> avoiding memory copies can improve efficiency significantly in my
Yeah this sounds useful to me.
I read really big files (~500GB) into Lua strings (for parsing with
lpeg), and it was annoying to do this without thrashing on systems with
only 1GB physical memory.
[Currently I mmap the file, use madvise(MADV_SEQUENTIAL), and then use
lua_pushlstring; this works OK, but of course that isn't portable...]
Bacchus, n. A convenient deity invented by the ancients as an excuse for