Skip to main content
Inspiring
June 14, 2013
Question

Where variables are stored in disk?

  • June 14, 2013
  • 1 reply
  • 3841 views

Hi friends

Just a question more for curiosity. It´s a technical concept question around programming.

Suppose I have a script which has variables declarated outside any function. So they are global variables.

When you are running the script, these variables "take a space in memory" and can receive values.

What´s the real concept aroud this "taking room or space in memory (or disk)"?

I mean, does the system running the script create any phisical file in the disk with the name or the variable waiting to receive (store) and read values inside? Like a text (*.txt) document???

Or the system processes global variables without creating any phisical document...and this space is disregard when concluding the running of script?

I´m using Windows 7 64 bits OS. If each variable was considered as a file, which folder is it stored? Could I check for any remaining unused variable? Could I open it? See it in disk?

Hope I was able to explain my curiosity

Thank you very much

Gustavo.

Message was edited by: Gustavo Del Vechio

This topic has been closed for replies.

1 reply

Inspiring
June 14, 2013

I think all variables, global and local, are stored in ram while the script is running. If you need to access a variable from another app while the script is running the script could write them to a file. A file can also be used to store variables between script runs. If the variables only needed to be accessed by Photoshop scripts you can also store variables in customOptions.

Inspiring
June 14, 2013

Hi Michael, thank you.

I know about the possibility to save data in text files. I use it sometimes.

So, could we conclude the variables, global or local are kept in ram only in the time the script is running? So, after the end of script, nothing are kept in disk? (concluding also variables are not files in disk, but spaces in ram memory?)

What means customOptions?

Thank you. I´m trying to improve my technical knowledge about programming. And did not find this kind of information anyplace.

Gustavo.

Inspiring
June 16, 2013

If by performance you mean speed, then I think it depends on script. Global variables are sometimes needed even with if you put everything in functions. And global variables are less of a problem in a Photoshop script than they are say in web browsers. But it is considered better to limit global variables to as few as possible and give then unique names. That is very important when creating a start-up script that will remain in memory the entire Photoshop session or with scripts that can be called from other scripts such as Fit Image.

Some another advantages of putting everything in functions are:

You can call the function as an argument to suspendHistory().

You can have a basic script template for creating new scripts.That template can already contain all the support methods like getting/setting preferences, create/update dropdownlist, keyboard event handlers, etc, It can also have placeholders for createDialog, runDialog, execute, etc. To create a new script you just modify the placeholder methods and add any other methods the script needs. Several of the Adobe scripts written by Tom Ruark use this approach.

I use that approach with creating scripts that have a dialog or other complex scripts. But I don't bother if it's a simple script. It takes more time to modify the template than it does to just start from scratch.

But I really think how you write your scripts is a matter of style. As long as you are not careless using global variable names and break other startup scripts. If using a main function makes sense to you then use that approach. If it seems like a lot of work for little return then don't. I don't think one way or the other makes much difference if both ways are writen with care, do what is required, and doesn't break other scripts.


Very good Michael

Wise words!!!!

I´m liking the concept of inserting all inside functions. It´s easy to manage (you could even use "Return" if the condition is not true. And the concept about "templates" for using code´s portions to other scripts are also a real good step. I have a function that analyzes an string and take off unecessary characters like 2 sequential spaces, spaces at the end of string, slashes and so on. I use it in various scripts I´m developing!!

Thank you for sharing your experience, Michael. It´s surelly a big learning!

Best Regards

Gustavo.