[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How far should one go preventing potential memory leaks?
- From: Thomas Jericke <tjericke@...>
- Date: Tue, 10 May 2016 09:10:39 +0200
On 05/10/2016 08:41 AM, Marc Balmer wrote:
This prevents a memory leak if lua_pushstring() raises an error, but I
up with a number of rather small allocations that are only used for a
period of time.
If they buffers are really that small, I would just use the stack.
snprintf(s, sizeof(s), "bumblebee");
After all, this doesn't use more stack space then having 4 local doubles
in your C function.
Wouldn't it be nice to have a explicit call in the Lua API to
free a userdata value immediately, e.g.
char *s = lua_newuserdata(L, 32);
snprintf(s, 32, "bumblebee");
Or do you think the garbage colletor overhead can be neglected?
I think such a function would only reduce memory overhead and not CPU
lua_freeuserdata(s) would have to check whether there is still a valid
reverence to that userdata.