Jump to content

Script property memory/performance question


Recommended Posts

Hello all!

 

If I have a property such as

actor property PlayerREF auto

and another script with this property, and another... and another.. and another..

 

my question is:

 

1.) does this take up a non-negligible amount of memory?

 

And if so,

 

2.) would it ever be preferable to use Game.GetPlayer() to save on this memory, especially on something that runs only once OnInit()?

 

I know the speed performance of using PlayerREF is better than GetPlayer() and has been discussed to death but I'm just using it as an example.

 

Edit: Follow up related question:

3.) would the answer to that question be the same for multiple arrays with many of the same references? Assuming they were each made independently of one another and not passed by reference to each other. For example, ArrayA has 37 references that I am interested in but I am also interested in a 38th item so I make a brand new ArrayB and make a function to fill it with those 38 items, passing each one in by variable (without passing ArrayA into it by reference).

 

If I'm being unclear please let me know.

 

Thank you guys and girls! :smile:

Edited by shatsnazzle
Link to comment
Share on other sites

You're not being unclear, exactly, but the only thing I can think of is: why? Unless you provide an example, it just sounds to me like you're making things needlessly complex.

 

As for property / variable memory size the answer is that it varies. An Objectreference property pointing to the player takes up minimal space because it only points to one thing at a time. But a full String can take up a lot more space because you can fill it up. The more technical answer is that it is a bit more complex, but in terms of memory it is close enough.

Edited by Reneer
Link to comment
Share on other sites

Thank you for the fast response Reneer! Needlessly complex is my favorite though:)

 

For questions 1 and 2 the reason I asked is just out of curiosity and because I don't think I would mind having a slower function do a time insensitive, rare, or one-time task if it means freeing up memory.

 

For question 3 I'm having a hard time putting my brain around what I'm trying to do in a way that can justify the complexity Lol. I think your question might have reminded me to reevaluate my approach so thank you for that :smile:

 

Essentially what I was trying to do with the arrays in question 3 was just not alter any vanilla data or scripts. I figured I'd make my own array with the extra item I need and use that whenever I needed the array. But I think I'll reexamine the big picture tomorrow with a clearer head and very possibly just scrap the array. Time for bed thank you again for the response :smile:

Edited by shatsnazzle
Link to comment
Share on other sites

The issue, in my mind, is that script execution time is generally more important then memory usage. The amount of memory you save by not using a property / variable is extremely small. If you call GetPlayer(), the script will slow down overall by X amount. Edited by Reneer
Link to comment
Share on other sites

Given that a property fill on PlayerREF is likely to use the same budget as Game.GetPlayer() if a script only refers to it once in passing, like a one time quest stage, it is sensible to use Game.GetPlayer() just to cut down on property management. If more than once or reoccurring then use a property.

 

This seems to be the policy used by base game scripts, not saying that's best practice, but common established behavior.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...