AutoHotkey Community

It is currently May 26th, 2012, 11:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 9th, 2009, 5:59 pm 
Offline

Joined: September 9th, 2009, 7:24 pm
Posts: 10
In AHK you can create variables on the fly, but I see no way to remove them. You can set them to empty or blank but the variable name itself remains. In essence, still taking up memory.

I would like to see a 'KillVar' or 'Destroy' or 'Remove' command that could free up that memory on the fly. This would be especially helpful if 'true' arrays are ever implemented.

I use AHK to extract data from CSV files that originate fom databases, then parse the data to format and narrow the list and finally give the user a GUI face for a few choices to select from. Sometimes it becomes quite 'messy' to keep creating new variables, or reuse a bunch of temporary variables, especially if I've been using them like an array and the number of elements dont match.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:36 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Quote:
You can set them to empty or blank but the variable name itself remains. In essence, still taking up memory.


I don't see an issue with the variable name itself, taking up memory. As you state, you know that you can clear the variable value or set it back to 0 as needed, what is the significance of killing the Variable namr itself?

If you kill the script, you kill the variable...

If you have the script up, you have the variable with a memory location, used or unused, it is still registered upon script initialzaion.



Quote:
I would like to see a 'KillVar' or 'Destroy' or 'Remove' command that could free up that memory on the fly
This seems equivilant to Variable := "" as the variable name itself takes up memory, weather or not it contains a value in the script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 10:42 pm 
Online
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Assigning an empty string to a variable only deletes the memory when it is bigger than 4 kB for performance reasons.
VarSetCapacity(var, 0) actually deletes the memory used by the variable.
Additionally AutoHotkey reserves allocate-only memory for a variable if its initial size is not bigger than 64 bytes (SimpleHeap), of course it changes to malloc'ed memory if you assign it a bigger string.
I think I should take a break from working with the AHK source :lol:

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 11:55 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Quote:
I think I should take a break from working with the AHK source


Disagree!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 4:32 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
fincs wrote:
VarSetCapacity(var, 0) actually deletes the memory used by the variable.
Technically it only frees the memory used by the contents of the variable. It does not free the variable itself; i.e. the "Var" structure which holds the name, length, capacity, method of allocation, cached binary number, attributes etc. (I think the Var structure is 32 bytes plus the size of the name, but I'm too lazy to confirm.)

FYI, most of this has been discussed before, but not since objects/arrays were introduced into AutoHotkey_L. Arrays within objects should use less memory on average than typical AutoHotkey pseudo-arrays. Items can be removed; currently doing so frees any associated strings (text) and allows the memory of the item itself to be later reused. If an object has excess memory (e.g. you've added and removed 1000 items), _SetCapacity can be used to shrink it.

There are also other, more important reasons to use arrays/objects...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 10:14 pm 
Online
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Lexikos, you're right. When I wrote that reply I meant to say the contents but failed horribly at doing so.
I should really stop trying to do things when I'm tired.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 2nd, 2010, 3:02 pm 
I would really love to have a delete variable feature!

I wrote a script that adds lots of hotkeys to an application. It starts at system boot and waits for that application window's class to activate.

There can be multiple processes running the application simultaneously, so the script has to create a large set of variables to store context for each process when that process's window is not active. These context variables have dynamic names like SelectedFeatureFlag%HWND%.

I have a timer that runs every x minute to check if all of the known processes for the application still exist. If any don't the timer routine does SetVarCapacity(var%HWND%, 0) for the unneeded context variables.

This works well, but if my computer is up for a week there can be 100s of these stale, empty variables left around. I realize they do not cause a performance issue, but they sure are annoying when I need to check a live process's context variables with View Variables and their contents.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 7:13 pm 
I agree, this feature is necessary. I generate large (as in hundreds of thousands) array entries as I parse data with autohotkey and when I am done all this memory is still "committed" in virtual memory even though I set the variables I am done with to "". I am running into issues where my virtual memory is exhausted and autohotkey can not create or add to any variables it has. A feature to delete this "committed" memory would be great.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 8:02 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Anonymous wrote:
A feature to delete this "committed" memory would be great.
Reload :wink:
Lexikos wrote:
FYI, most of this has been discussed before,
Could you provide a link to the relevant thread? I've yet to see a convincing argument for the necessity of this feature, but there seems to be a vocal minority who are unable to script without it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 10:30 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
This seems related: EmptyMem()

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 5:22 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
jaco0646 wrote:
Could you provide a link to the relevant thread?
I don't recall where it was, but there probably wasn't anything important mentioned that hasn't been mentioned here.
Quote:
I've yet to see a convincing argument for the necessity of this feature,
I agree, but then no such argument is possible from my perspective. It just seems like a poor workaround for the lack of proper arrays.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 5:59 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Lexikos wrote:
It just seems like a poor workaround for the lack of proper arrays.
I agree with Lexikos - and since he can't properly edify himself, I will. IMO, object/array support is the best enhancement to AHK since I started using it. Great work Lexikos - this is something that, IMO, needs to be included in the standard release of AHK. It would solve many issues, including this thread.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group