Jump to content


VarSetCapacity(VarName [,Capacity,FillByte, ReturnAddress])


  • Please log in to reply
10 replies to this topic

#1 Guests

  • Guests

Posted 28 February 2012 - 05:12 AM

What about an option to return the address of created variable? Something like, VarAddress := VarSetCapacity(UnquotedVarName [, RequestedCapacity, FillByte, ReturnAddress]).

So the function can be passed to a funciton parameter where it requests a memory address.
DllCall("wsprintf", "ptr", VarSetCapacity(buf, max_bytes, 0, [color=red]True[/color]), "str", "0x%08x", "uint", 4919)


#2 VxE

VxE
  • Fellows
  • 3504 posts

Posted 28 February 2012 - 08:15 AM

-1 for frivolousness.
DllCall("wsprintf", "ptr", VarSetCapacity(buf, max_bytes, 0, True) [color=red]? &buf : 0[/color], "str", "0x%08x", "uint", 4919)
... 'Nuff said.

#3 Guests

  • Guests

Posted 28 February 2012 - 08:23 AM

DllCall("wsprintf", "ptr", VarSetCapacity(buf, max_bytes, 0, [color=red]True[/color]) ? &buf : 0, "str", "0x%08x", "uint", 4919)
... 'Nuff said.

So you are supporting the idea, nuff said.

#4 VxE

VxE
  • Fellows
  • 3504 posts

Posted 28 February 2012 - 08:38 AM

My mistake, I meant to omit the extra , True from the code blurb.

The code is meant to illustrate how you can enjoy all the benefits of your wish immediately, without waiting for Lexikos to update AHK.

Don't freak out so much when people disagree with your wishes. You have to understand that adversity is necessary for productive growth.

#5 Guests

  • Guests

Posted 28 February 2012 - 08:45 AM

The idea is meant to push the program to be more useful.

Don't freak out so much if you see someone's idea that you cannot understand.

You have to understand what suggestion means. It is meant for productive growth.

#6 Zaelia

Zaelia
  • Members
  • 705 posts

Posted 04 March 2012 - 04:35 PM

I am disagree and agree...

- VarSetCapacity() is not a good name and too long as UrlDownloadToFile, Variable() is more readable as Download.
- The name is not well designed, because in normal way we only use it for create a memory space, and we need more an address return by default than a size return. But the size returned is the good way to know if the function failed (but for expand and very rare)...
- First param is not an expression, we need to discard this exception and use a real expression (not myvar but "myvar")
- Size could be replaced by "Ptr" for example, or other string type, just for a good read, or dynamic in case of a pointer.
- We could have a fill bites option, because we use a lot of pre-structure or cooked buffer, for example "00F0000200FF" as a multi-numput() shortcut.
- and maybe other feature, I generally use a custom variable function or without with more line to write, "the possibility already exist" is not a good argument...

Therefore, majority of case, for one line script, for expand possibility, et caetera, this can be more short and readable... But I think it's for V2, now we can do it but we need to upgrad/change for the future !

#7 Guests

  • Guests

Posted 04 March 2012 - 08:54 PM

The idea is meant to push the program to be more useful.

"More useful" for a small group of users more likely, I doubt the majority of people using ahk will even understand what you mean and what the purpose is. So perhaps explain it a bit better, like you would a five year old or your golden retriever.

#8 maul.esel

maul.esel
  • Members
  • 790 posts

Posted 04 March 2012 - 09:04 PM

VarSetCapacity() is not a good name and too long as UrlDownloadToFile, Variable() is more readable as Download.

Variable() is misleading - it doesn't create a variable, it sets a variable's capacity.

First param is not an expression, we need to discard this exception and use a real expression (not myvar but "myvar")

First param is an expression, no need to change.

Size could be replaced by "Ptr" for example, or other string type, just for a good read, or dynamic in case of a pointer.

Could you explain that further? I don't really understand what you mean.

We could have a fill bites option, because we use a lot of pre-structure or cooked buffer, for example "00F0000200FF" as a multi-numput() shortcut.

Personally, I wouldn't find this useful. I know I want to put a "4" in there, from (for example) a structure definition I can say it's an Int - but I couldn't tell what value each byte has.

Original topic: Personally, I don't think this is an important feature, I like the current design.
-1

#9 VxE

VxE
  • Fellows
  • 3504 posts

Posted 04 March 2012 - 10:20 PM

Actually, Zaelia's description has sort-of changed my mind on this, with a few modifications of course.

I can see the value of a function that wraps allocation and initialization and returning the variable's address under one umbrella, but does not replace VarSetCapacity().

The function name and arrangement of its parameters is something I haven't pinned down, but here's the basic points:

1. Allocate space for a variable and return the variable's address.
2. Accept a 'fill_data' parameter that defines the variable's default contants. I was thinking that this could either be a byte value, a short value (i.e: a 'fill_char' for unicode) or a hex string (to easily define a struct for receiving data).
3. Have an option to replicate the 'fill_data' until the capacity is initialized (I know a quick way to do this).

Actually, this seems like a general-purpose version of the mcode() function.

#10 Zaelia

Zaelia
  • Members
  • 705 posts

Posted 05 March 2012 - 07:21 PM

It is difficult to define (ahk is just a hobby for me and english is not my tongue):
- maybe if we really need then we can create a new function, or use a generic name
- maybe it is too close of a structure definition, or not very usefull
It was just a list of ideas (quick thoughts)... and yes, they already are mcode.ahk or struct.ahk or other libraries that can enlarge the view, but I really think that V2 team need to think about this, perhaps if it is already supported then I am sorry.
However I am still against this one simple addition that suggests the guest.

#11 VxE

VxE
  • Fellows
  • 3504 posts

Posted 14 March 2012 - 01:35 AM

Well, I slammed out a working solution to this wish: <!-- m -->http://www.autohotke...pic.php?t=83760<!-- m -->