Thread Tools Display Modes
05-16-06, 07:45 PM   #1
rophy
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 24
memory efficiency?

The mod I'm currently working on will pass a table with a "type" variable to a function. the function will check the "type" to see what variables are contained in the table.

I think that if 'type' is numbeirc rather than string, it should result in less memory consumed. But does it actually makes a difference? Or the impact is so neglible that I can just use string on 'type' so that it's more human readable?

What I meant was:


COMBAT_HIT = 103;
if result.type == COMBAT_HIT then bla bla bla

VS

if result.type == "COMBAT_HIT" then bla bla bla

Do they make a difference on memory?, if this is called frequently?

I did make a simple test myself, and it seems that the difference is negliable?
  Reply With Quote
05-17-06, 12:31 PM   #2
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
If you're always dealing with constants (i.e. you're not dynamically composing the string from something else) then they're essentially equivalent. Lua uses interned strings, so all instances of "COMBAT_HIT" are stored as references to the same common string object. A string comparison ends up being essentially a pointer comparison, just as fast as a number comparison.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » memory efficiency?


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