My program process a text file. Part of the process is more efficiently executed with all the content of the file in one string variable. This is the only large variable in the script.
To allow processing of files larger than 64 MB, I need to increase the maximal variable size using the #MaxMem instruction.
But how do I know how much I can increase the size of variables without exceeding the memory capacity of the PC?
In other words, two questions:
1) Is there a DLLCall function that would tell me how much RAM is available to my script?
2) From my understanding, I could not ajust the #MaxMem directive according the the RAM available. But is there another approach to this issue?
Thanks!
#MaxMem: How much is too much?
#MaxMem: How much is too much?
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
- LinearSpoon
- Posts: 156
- Joined: 29 Sep 2013, 22:55
Re: #MaxMem: How much is too much?
FileRead already ignores #MaxMem and just reads the whole file into a variable.
If you're really worried about coming across a huge file that would exceed your RAM, try a file parsing loop or a file object to only read a portion at a time...
If you're really worried about coming across a huge file that would exceed your RAM, try a file parsing loop or a file object to only read a portion at a time...
Re: #MaxMem: How much is too much?
Hum... That's good to know. Thank you for this info. Of course, if I read a file bigger than available RAM, the script will break.LinearSpoon wrote:FileRead already ignores #MaxMem and just reads the whole file into a variable.
Yes, this is my fallback solution. But since some processing has to be applied to the content as a whole (for example, determine a character that is *not* actually used in the file), this will require a bit of additional coding.LinearSpoon wrote:If you're really worried about coming across a huge file that would exceed your RAM, try a file parsing loop or a file object to only read a portion at a time...
Until I can do that, i was wondering if a command (DLLCall?) could tell me how much memory is available, check the file size and display a clean error message if the RAM is not sufficient.
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: #MaxMem: How much is too much?
If a) you exceed #MaxMem or b) a memory allocation fails due to insufficient free memory, you get an error message and the current script thread is aborted. Either way, basically the same result, so having an artificial limit isn't at all useful for allowing your script to work. Instead,
If your script is functioning as intended and you're reaching the limit, I'd suggest adding #MaxMem 4095 and then forgetting about it. It's really not very useful, and has actually been removed from v2 (i.e. there's no arbitrary limit).The purpose of limiting each variable's capacity is to prevent a buggy script from consuming all available system memory.
Re: #MaxMem: How much is too much?
Good points, Lexikos. Then, I could spot in my code the commands that could make the script reach the "Out of memory" limit and use Try/Catch to return a proper error message to the user.
Are the Try/Catch very processor intensive if inserted in a very critical section of a script? If yes, instead of using Try/Catch in every iteration of a critical loop, I could run it only once in a while creating
a phony large variable?
Thank you all again for your sound advice.
Are the Try/Catch very processor intensive if inserted in a very critical section of a script? If yes, instead of using Try/Catch in every iteration of a critical loop, I could run it only once in a while creating
a phony large variable?
Thank you all again for your sound advice.
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: #MaxMem: How much is too much?
Check out jNizM's script here http://www.auto-hotkey.com/boards/viewt ... ?f=6&t=142
MemoryInfo v0.1
Info about Memory:
Total, Free & Used Memory, Clear Memory
MemoryInfo v0.1
Info about Memory:
Total, Free & Used Memory, Clear Memory
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Re: #MaxMem: How much is too much?
Yes! Just found the reply from jNizM to a similar discussion on the old forum. Exactly what I was looking for.
With this, no need to Try/Catch. I'll remove the #MaxMem restriction and test if enough RAM is available before loading a file in a variable.
Thanks!
With this, no need to Try/Catch. I'll remove the #MaxMem restriction and test if enough RAM is available before loading a file in a variable.
Thanks!
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: #MaxMem: How much is too much?
update:
DLL-Function for Memory
DLL-Function for Memory
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Who is online
Users browsing this forum: No registered users and 110 guests