Memory allocations

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

User avatar
Evil-Dog
Posts: 86
Joined: 08 Mar 2011, 17:59
Contact:

Memory allocations

Postby Evil-Dog » 13 Apr 2015, 14:45

Hi there
I was wondering something, I use a lot of extension requests, for starting to shoot the gun, when jumping, triggering items, etc lots and lots.
So there's a lot of allocations for the SFSObject like this (from your BattleFarm exemple)

Code: Select all

var paramsObj:SFSObject = new SFSObject();
paramsObj.putInt("bId", i);
paramsObj.putInt("bx", px);
paramsObj.putInt("by", py);
refDocument.smartFox.send(new ExtensionRequest("bb", paramsObj));


The same thing happens when sending user variables such as this:

Code: Select all

if(m_PlayerPawn.m_vLocation.X != m_fNetPawnLocationX)
   m_UserVars.push(new SFSUserVariable("PosX", m_PlayerPawn.m_vLocation.X, VariableType.DOUBLE));
if(m_PlayerPawn.m_vLocation.Y != m_fNetPawnLocationY)
   m_UserVars.push(new SFSUserVariable("PosY", m_PlayerPawn.m_vLocation.Y, VariableType.DOUBLE));


Isn't that worrying with the constant allocating and the garbage collector? Every list of things to do to optimize your game includes cutting down on the constant object allocations like that. I was thinking of reusing the same SFSObject and just create it once but there's no "clear" method to remove all its keys or anything. It would be tedious to remove the specific named keys (still doable). In the case of user variable maybe i could keep an instance for it and change its values I think? Would that even work? What are your thoughts on the best way to go about reducing allocations on that front?
Thank you very much
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Memory allocations

Postby Lapo » 14 Apr 2015, 07:40

In general I would not reuse SFSObjects, they're not done for reuse.

Everything you do creates new objects which need to be deallocated at some point. If you could clean up the content of an SFSObject that alone would dereference all of the data in it, thus creating garbage. :) The only way not to allocate memory is doing nothing! :mrgreen:

Objects such as SFSObject are extremely light. It's essentially just a container for your data, and it's unlikely to cause any issues unless you are going to create thousands per second.

I would not worry about it.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Evil-Dog
Posts: 86
Joined: 08 Mar 2011, 17:59
Contact:

Re: Memory allocations

Postby Evil-Dog » 14 Apr 2015, 13:35

Alright cool, thanks for the info :)

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 14 guests