v2.0-beta.1 Buffer object

Discuss the future of the AutoHotkey language
just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

v2.0-beta.1 Buffer object

Post by just me » 26 Jul 2021, 07:52

Thanks for releasing the v2 beta, I didn't expect to live to see it. ;)

I started to work with Buffer objects. Once I did it, I'm missing a built-in method to reinitialize an object, e.g. Buffer.Init(0). Any chance to get it?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: v2.0-beta.1 Buffer object

Post by swagfag » 26 Jul 2021, 08:41

Code: Select all

#Requires AutoHotkey v2.0-beta.1
Buffer.Prototype.DefineProp('Init', {Call: (this, FillByte := 0) => DllCall('ntdll\RtlFillMemory', 'Ptr', this, 'Ptr', this.Size, 'Int', FillByte)})

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: v2.0-beta.1 Buffer object

Post by just me » 26 Jul 2021, 09:17

@swagfag, I'd prefer a built-in method and if not available

Code: Select all

Class ReusableBuffer Extends Buffer {
   Clear(FillByte := 0) => DllCall('Ntdll.dll\RtlFillMemory', 'Ptr', This, 'Ptr', This.Size, 'Int', FillByte)
}
which does not touch the prototype.


swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: v2.0-beta.1 Buffer object

Post by swagfag » 28 Jul 2021, 03:34

u can. if u dont care about .Ptr possibly (likely) changing

lexikos
Posts: 9494
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2.0-beta.1 Buffer object

Post by lexikos » 28 Jul 2021, 03:48

If you specify only the second parameter, __New will just call memset, and the value of Ptr cannot change.

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: v2.0-beta.1 Buffer object

Post by just me » 28 Jul 2021, 04:06

This method exists to support Call, and is not intended to be called directly.
:(

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: v2.0-beta.1 Buffer object

Post by swagfag » 28 Jul 2021, 04:32

lexikos wrote:
28 Jul 2021, 03:48
If you specify only the second parameter, __New will just call memset, and the value of Ptr cannot change.
ah, nifty. but that ought to be documented then. otherwise its unexpected that specifying a bytecount the same as the old one would result in a realloc, whereas not specifying it wouldnt

Post Reply

Return to “AutoHotkey Development”