Memory optimization with UnitName, UnitMana ...
Hi everybody;
First, i would like that i'm french, so sorry for my poor english :confused: I'm developping my own addon for raid management. I'have installed RessourceTool in order to check how many memory is used by my addon. And i notice a strange behavior : when i use function like "UnitMana", "Unithealth", Unitxxx; the memory increased until the Garbage Collector do his job. When i dont use Unitxxx, the memory addon is constant (about 100ko), when i use Unitxxx, the memory grows (about 500ko) and the descrease to 100kon, and then grows...etc Somebody already notice it and know what to do ? |
Can you show the part of the code that calls that? It's probably more about how you used those functions that about the functions themselves.
(Sorry about that, but I just have to: C'est rare de voir un compatriote sur ce site, Salut ^^) |
Hi,
This this the function i use : function My_UnitMana(unitid) return UnitMana(unitid) or ""; end ... And i call it like this : table.insert(tmpmess, tostring(My_UnitMana(unit))); If i replace my function by this (for test): function My_UnitMana(unitid) --return UnitMana(unitid) or ""; return 1; end the memory is constant. I understand that Unitxxx use memory, but i dont understand why it growing ... :confused: (Petite parenthese : salut l'ami ! en esperant que mon anglais ne soit pas trop mauvais ! Je prefere repondre en anglais histoire de respecter la langue du forum ;) ) |
Forget my post ...
Its not Unitxxx which is the problem. I try with function My_UnitMana(unitid) --return UnitMana(unitid) or ""; return 9999; end and i have the same problem. As you said, it how i manage my variable ,) Im gonna check this way |
Well what takes space is your table. You are inserting things in a table, so unless you remove that afterward, the table will grow. Let's say your are calling your function on a mage that is DPSing randomly: the table after the mage has stopped will look like:
{9500,9250,9000,8750,8500,....,500,250,0} Now, if you were also targeting other people from time to time, their data would be added too. Why do you want to do with those values? Cause actually, maybe you're doing something nice with them, but if you don't remove them from time to time, you'll end up with a {0,1,2,3,4,5,6,7,8,9,...,12000} table which won't be of a great help for anything ;) |
Thanks for your help.
In fact, i see that string concatenation take lot of memory and that is more usefull on my case to use table and then concat it. Exemple : tmp = ""; for i=1; 40; do tmp = tmp .. "1"..a.."2"..b.."3"..c.."4"..d..<......> .."40"... ; (for exampl) end It seems to take lot memory so i use a table. I found code on the ACE2 website (http://www.wowace.com/wiki/Coding_Tips) local cache = setmetatable({}, {__mode='k'}) data= next(cache) or {}; table.insert( data, < value > ) ... for j in pairs( data) do data[j] = nil -- this section clears the temporary table end cache[data] = true So i change my code to (but im really not sure i choose the best way ...): local cache = setmetatable({}, {__mode='k'}) data= next(cache) or {}; for i=1;40; do table.insert( data, tostring(i) ); table.insert'(data, tostrinf(My_UnitMana("raid"..k))); end print( table.concat(data, "")); for j in pairs( data) do data[j] = nil -- this section clears the temporary table end cache[data] = true (This a simple exampl) Its the first time i'm developping an addon but i would like it dont take to much memory, that why i would to optimiz it; and i saw that "string" can be optimized... so i try ;) |
I think that the part that doesn't work is the one that clears the table. I also think that it's not really needed to have both the use of a metatable-cache via the "mode='k'" and a manual clear.
Here, a simple table will do just fine, I think. Start with Code:
local data = {} Code:
for key,_ in ipairs(data) do If it still does the same, well, I just said a whole bunch of crap, sorry :/ |
All times are GMT -6. The time now is 07:34 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI