Page 1 of 1
v2.0-beta.1 Buffer object
Posted: 26 Jul 2021, 07:52
by just me
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?
Re: v2.0-beta.1 Buffer object
Posted: 26 Jul 2021, 08:41
by swagfag
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)})
Re: v2.0-beta.1 Buffer object
Posted: 26 Jul 2021, 09:17
by just me
@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.
Re: v2.0-beta.1 Buffer object
Posted: 28 Jul 2021, 02:59
by lexikos
Re: v2.0-beta.1 Buffer object
Posted: 28 Jul 2021, 03:34
by swagfag
u can. if u dont care about .Ptr possibly (likely) changing
Re: v2.0-beta.1 Buffer object
Posted: 28 Jul 2021, 03:48
by lexikos
If you specify only the second parameter, __New will just call memset, and the value of Ptr cannot change.
Re: v2.0-beta.1 Buffer object
Posted: 28 Jul 2021, 04:06
by just me
This method exists to support Call, and is not intended to be called directly.
Re: v2.0-beta.1 Buffer object
Posted: 28 Jul 2021, 04:32
by swagfag
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