lua-users home
lua-l archive

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


On Sun, Feb 05, 2006 at 12:22:26AM +0200, Asko Kauppi wrote:
> Hm, I was thinking of suggesting that (local buffer) to David, but  
> that's way too bad design considering multithreaded applications.
clearly the only reasonable use of static buffers is by the main routine.

> But having the local buffer in stack (not 'static') is safe; David,  
> is that an option?
> 
> {
> 	char buffer[80];
> 	int length = myapi(NULL, 0);
> 	assert( length <= sizeof(buffer) );
> 	(void) myapi(buffer, length);
> 
> 	lua_pushlstring(L, buffer, length);
> }
> 
> Of course, one can resort to the malloc code, if length turns out to  
> be too big (instead of assertion).
on stack, of course.
For MT environments, 2MB stack is typical,
so using about 64-256K or so in a non-recursive function is usually
considered acceptable.
For ST you can use much more on most platforms.