Thread Tools Display Modes
Prev Previous Post   Next Post Next
05-03-10, 11:59 PM   #1
corveroth
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 29
Maintaining a sortable database, garbage creation

I have an issue, to the tune of 80 KB of junk every time COMPANION_UPDATE fires.

For my addon, I find it necessary to keep up to date information on your companions. Beyond simply registering COMPANION_UPDATE and calling GetCompanionInfo, I also pull some extra data from tooltips and hard-coded tables, in order to offer more information to the user (such as mount speed).

The issues arose when I added in the capacity to sort that data. Three columns appear in the display, and the tabs at the top of each enable sorting, much like the Guild or Who frames. To allow for this behavior, I found it necessary to store several pieces of information in a table, which I could later sort, and whenever the display needed to be refreshed, I read off the appropriate rows from the table. The problem appears to lie in the need to rebuild the entire table every time that COMPANION_UPDATE fires (very common in cities, as it fires for nearby players as well).

What recommendations might you have to offer to cut down on the garbage generation inherent to this approach? What alternative approaches might exist?

lua Code:
  1. local MountData = {}
  2. local function UpdateMountData()
  3.     MountData = {}
  4.     local creatureName, spellID, icon, active
  5.     local speed, mountType, numPassengers, isUsable, varies
  6.     local notes
  7.    
  8.     for i=1, GetNumCompanions("MOUNT") do
  9.         notes = ""
  10.         _, creatureName, spellID, icon, active = GetCompanionInfo("MOUNT", i)
  11.         -- GetExtraCompanionData is my function that does the tooltip scanning and such
  12.         speed, mountType, numPassengers, isUsable, varies = unpack(GetExtraCompanionData("MOUNT", spellID),1,5)
  13.        
  14.         if numPassengers > 0 then
  15.             -- NOTE: addLine is just a utility function to insert newlines as appropriate
  16.             notes = addLine(notes, format(L["Passengers: %d"], numPassengers))
  17.         end
  18.        
  19.         if varies then
  20.             notes = addLine(notes, L["Varies"])
  21.         end
  22.        
  23.         if not strfind(notes, "\n") then
  24.             if mountType == MOUNTTYPE_LAND then
  25.                 notes = addLine(notes, L["Ground"])
  26.             elseif mountType == MOUNTTYPE_FLYING then
  27.                 notes = addLine(notes, L["Flying"])
  28.             elseif mountType == MOUNTTYPE_AQUATIC then
  29.                 notes = addLine(notes, L["Aquatic"])
  30.             end
  31.         end
  32.        
  33.         tinsert(MountData, {NAME = creatureName, NOTES = notes, SPEED = speed, ICON = icon, ACTIVE = active, ISUSABLE = isUsable, ID = i})
  34.     end
  35. end

Last edited by corveroth : 05-04-10 at 12:13 AM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Maintaining a sortable database, garbage creation


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off