#MaxMem: How much is too much?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
JnLlnd
Posts: 297
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
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!
Author of freeware apps Quick Access Popup (http://www.quickaccesspopup.com),
FoldersPopup and CSV Buddy (http://code.jeanlalonde.ca)
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: 297
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
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.
Author of freeware apps Quick Access Popup (http://www.quickaccesspopup.com),
FoldersPopup and CSV Buddy (http://code.jeanlalonde.ca)
lexikos
Posts: 6657
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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: 297
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
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.
Author of freeware apps Quick Access Popup (http://www.quickaccesspopup.com),
FoldersPopup and CSV Buddy (http://code.jeanlalonde.ca)
User avatar
DataLife
Posts: 330
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: 297
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
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!
Author of freeware apps Quick Access Popup (http://www.quickaccesspopup.com),
FoldersPopup and CSV Buddy (http://code.jeanlalonde.ca)
User avatar
jNizM
Posts: 2530
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: #MaxMem: How much is too much?

04 Oct 2013, 12:45

[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 210 guests