generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Hey quick question about memory

Previous Thread :: Next Thread 
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
01 Sep 2015 08:58 PM
What saves more memory and what should I use for things that could lag.

--Create a local value for every item in v
for _,v in pairs(list)do
local name = v[1]
local price = v[2]
end


-- or reassign an already set value
local name,price
for _,v in pairs(list)do
name = v[1]
price = v[2]
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Sep 2015 09:01 PM
They're the exact same
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
01 Sep 2015 09:04 PM
^well the latter would leave a memory leak
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Sep 2015 09:05 PM
Not really a memory leak since chances are it would be in a function or something that would eventually terminate, but in terms of what he posted they would be the exact same.
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
01 Sep 2015 09:06 PM
Could you explain how they are the same if one is created a bunch of values?
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
01 Sep 2015 09:10 PM
You don't have to worry about memory on ROBLOX.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
01 Sep 2015 09:10 PM
"Not really a memory leak since chances are it would be in a function or something that would eventually terminate"
the only reason it's not really a memory leak is because lua is going to auto garbage collect it anyway but they both definitely have a longer lifetime than needed in the second since they're still active outside of their scope (that it should be in).
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Sep 2015 09:11 PM
'if one is created a bunch of values?' Please rephrase.

Anyways, the way local variables work is that they practically have no overhead. When you 'set a local variable' you are just loading some constant into a 'register'. However doing 'local name, price' on the top you might assume it would take some instructions but simple optimizations (where declaring local variables without a value are really just 'ignored' in a way) they end up doing EXACTLY the same thing. What happens after is different (registers won't be reused in example 2), but what's happening is the same:

Script 1:
for loop
load constant in register 0 the value of v[1]
load constant in register 1 the value of v[2]

Script 2:
load nil register 0 -> register 1 (however this instruction is actually optimized away)
for loop
load constant in register 0 the value of v[1]
load constant in register 1 the value of v[2]
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Sep 2015 09:13 PM
Lordrambo, I'm not disagreeing with you, doing the second one is pretty stupid but I'm just saying in terms of what's happening they're the same.
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
01 Sep 2015 09:17 PM
Thankyou
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
01 Sep 2015 09:18 PM
yeah they're going to produce the same output, the assembly dump will be a tiny bit different

I'm sick as hell right now so I might've articulated that last post poorly
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Sep 2015 09:25 PM
The assembly dump will be the exact same for the code he's given (unless more stuff comes after it), that's the point I'm trying to make.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
01 Sep 2015 09:42 PM
yeah in that case it would be
the "pseudo-memory leak" flaw that I pointed out relies on there being more code which there probably will be since he just set some variables
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image