Disabling all add-ons and leaving active only the one created by me, I noticed large swings in memory consumption. This is probably because in
OnUpdate event is launched this function, where tables are created all the time:
Lua Code:
local function tokenize(C, strng)
local sChar = string.format('%c', C)
local sInput = strng or ""
local tReturn = {}
for sWord in string.gmatch(sInput, "[^"..sChar.."]+") do
table.insert(tReturn, tonumber(sWord) or sWord)
end
return tReturn
end
local function gettok(sInput, iPosition, Separator, iRange)
local tTokens = tokenize( Separator, sInput )
if iPosition == 0 then return sInput end
local iStart, iStop = (iPosition > 0) and iPosition or (#tTokens + iPosition + 1)
if not iRange or iPosition == iRange then
return tTokens[iStart]
end
if iRange > 0 then
iStop = iRange
elseif iRange == 0 or (iStart + iRange) > #tTokens then
iStop = #tTokens
else
iStop = iStart + iRange + 1
end
if iStart == iStop then return tTokens[iStart] end
if iStart > iStop then
iStart, iStop = iStop, iStart
end
return table.concat(tTokens, Separator, iStart, iStop)
end
Where
• sInput = string to manipulate
• iPosition = position of the token inside the string. If lesser than 0, it will be considered the position from the last token to the first. If equal to 0, returns the whole string.
• Separator = ASCII code of the token separator
• iRange = optional: if specified, returns the token from position to range. If equal to 0, return all tokens from position to the end of the string.
Some examples:
local text = "apple.banana.cherry.grape.orange"
gettok(text,1,46)
> apple
gettok(text,-2,46)
> grape
gettok(text,2,46,4)
> banana.cherry.grape
gettok(text,-1,46,-3)
> cherry.grape.orange
Now, can you give me some advice on how to eliminate these fluctuations in memory usage by bringing, as much as possible, some small example, and improve this code?
Thank you in advance