Questions about DllCall() & VarSetStrCapacity()

Discuss the future of the AutoHotkey language
iseahound
Posts: 571
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Questions about DllCall() & VarSetStrCapacity()

06 Jun 2020, 09:10

I assume VarSetStrCapacity() is now solely for optimizing string concatenation.

1. Does VarSetStrCapacity() initialize the memory in any way? I checked GitHub, and it doesn't, but I want to be sure.

2. It looks like passing a string to NumPut() is not recommended. The buffer object seems to be preferred. If passing a string were to be removed, would passing the address of the string still work?

3. Is the buffer object faster than VarSetStrCapacity() + RtlZeroMemory?
Helgef
Posts: 4450
Joined: 17 Jul 2016, 01:02
Contact:

Re: Questions about DllCall() & VarSetStrCapacity()

06 Jun 2020, 13:38

I assume it is for strings, not any other binary data.

1, I assume it initialise a blank string, so puts one zero at the beginning of the buffer.
2, yes
3, probably the last thing to consider.

I couldn't access the varstrcapacity docs :cry:

Cheers
lexikos
Posts: 6975
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Questions about DllCall() & VarSetStrCapacity()

06 Jun 2020, 16:04

VarSetStrCapacity is the same as VarSetCapacity, aside from:
  • The second parameter and return value are in characters, not bytes.
  • No FillByte parameter (acts like it's always omitted).
  • VarSetStrCapacity(v) throws an exception if the variable contains a pure number or object.
The documentation wasn't uploaded because I forgot to add it to git.

If you want to know whether something is faster, benchmark it, in the context that matters to you.
iseahound
Posts: 571
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Questions about DllCall() & VarSetStrCapacity()

02 Aug 2020, 05:39

4. Is the buffer object compatible with VarSetStrCapacity? The docs say passing an object should throw... but my code works fine.
Helgef
Posts: 4450
Joined: 17 Jul 2016, 01:02
Contact:

Re: Questions about DllCall() & VarSetStrCapacity()

02 Aug 2020, 06:16

Is the buffer object compatible with VarSetStrCapacity
What does compatibility mean in this context? The answer is no though.
The docs say passing an object should throw
no it doesn't, it says,
An exception is thrown under any of the following conditions:
VarName is not a valid variable reference. It is not possible to pass an object property or built-in variable by reference, and therefore not valid to pass one to this function.
Consequently,

Code: Select all

varsetstrcapacity a:=bufferalloc(1),1	; yes
varsetstrcapacity bufferalloc(1),1 		; no
Cheers.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 12 guests