VarSetCapacity -1: updating string length v. capacity Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 3010
Joined: 19 Dec 2016, 01:58
Location: UK

VarSetCapacity -1: updating string length v. capacity  Topic is solved

20 Nov 2017, 21:37

I believe that using VarSetCapacity, and specifying -1, updates the perceived the length of the string, but doesn't alter the capacity of the variable. AFAICS, the documentation doesn't explicitly state that the capacity will remain the same.

VarSetCapacity()
https://autohotkey.com/docs/commands/VarSetCapacity.htm

Code: [Select all] [Download] GeSHi © Codebox Plus

In v1.0.44.03+, specify -1 for RequestedCapacity to update the variable's internally-stored string length to the length of its current contents.


According to this test, the capacity does remain the same.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



This is important in a situation where text is being repeatedly retrieved to the same buffer at a specific address, but where VarSetCapacity -1 is being used so that the text is ready to be appended to a growing variable or pushed into an array.

Anyway, I believe I've answered my own question, but I'll leave it here in case it can be interesting to others. Thanks for reading.

[EDIT:] In the example above, the address stayed constant. If the variable had been decreasing in size each time we did VarSetCapacity -1, then there might not be enough space for the next string due to be placed there.

An example of the address shifting as the variable size is increased.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot] and 35 guests