> Each file opened in lua, has an associated luaL_Stream structure?
> If so, is it possible to think about moving the buffer (luaL_Buffer) to
> this structure?
> Would it be possible, in this way, to use this buffer, instead of the local
> buffer?
What would be the gains?
More fine control over buffer used by file operations.
1. Matchs size buffer with luaL_buffinitsize, instead of using luaL_buffinit.
fw = assert(io.open("mybigfile.dat", "rb"))
assert(fw:setvbuf("full", 8192 * 2))
2. Bypass, internal buffer fread / fwrite operations.
luaL_buffinitsize (L,
&LS->b
, 8192 * 2);
int res = setvbuf(f, &LS->b, _IOFBF, 8192 * 2);
if called setvbuf, with NULL, a new buffer (size sz) is allocated and used.
if called setvbuf, with a buffer already allocated, fread/fwrite operations use this buffer,
avoiding copies.
3. Makes it possible to reuse the buffer for other operations.
Disadvantages:
1. Buffer need allocated before operations, but, if user
uses setvbuf, this already occurs, but the memory is allocated in libc.
regards,
Ranier Vilela