#MaxMem: How much is too much?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

#MaxMem: How much is too much?

03 Oct 2013, 09:21

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!
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: #MaxMem: How much is too much?

03 Oct 2013, 10:21

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...
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: #MaxMem: How much is too much?

03 Oct 2013, 12:29

LinearSpoon wrote:FileRead already ignores #MaxMem and just reads the whole file into a variable.
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: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...
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.

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.
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: #MaxMem: How much is too much?

03 Oct 2013, 21:53

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,
The purpose of limiting each variable's capacity is to prevent a buggy script from consuming all available system memory.
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).
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: #MaxMem: How much is too much?

03 Oct 2013, 22:11

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.
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: #MaxMem: How much is too much?

04 Oct 2013, 08:07

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
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: #MaxMem: How much is too much?

04 Oct 2013, 08:53

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!
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: #MaxMem: How much is too much?

04 Oct 2013, 12:45

[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, mcd, NullRefEx, supplementfacts and 140 guests