lua-users home
lua-l archive

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


On Mon, Apr 21, 2014 at 08:17:57PM -0700, Coroutines wrote:
> On Mon, Apr 21, 2014 at 5:30 PM, William Ahern
> <william@25thandclement.com> wrote:
> 
> > The C stack. Here's the luaL_Buffer definition:
> >
> >   typedef struct luaL_Buffer {
> >     char *b;  /* buffer address */
> >     size_t size;  /* buffer size */
> >     size_t n;  /* number of characters in buffer */
> >     lua_State *L;
> >     char initb[LUAL_BUFFERSIZE];  /* initial buffer */
> >   } luaL_Buffer;
> >
> >
> 
> ahh I see, so for strings larger than LUAL_BUFFERSIZE it fills the
> initb and puts the rest in heap storage, then computes the hash for
> pooling over both areas?

When initb is filled** it moves the entire buffer over to a heap allocated
block. It never uses multiple blocks to store buffer contents. For Lua 5.2
you can see the logic in luaL_prepbuffsize in lauxlib.c near line 437.


** Or, in the case of luaL_prepbuffer, when as much as a single byte has
already been written to initb, because luaL_prepbuffer guarantees
LUAL_BUFFERSIZE bytes of contiguous space.