class, this.setCapacity("buf",bytes) and passing buf as parameter

Get help with using AutoHotkey and its commands and hotkeys
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

class, this.setCapacity("buf",bytes) and passing buf as parameter

24 Sep 2019, 13:45

Hello
I try to rebuild my FFT project to class and I stuck at the passing objects buff as parameter to my functions.
In case where I alloc buffs using varSetCapacity(buf,bytes,0) then I can use tst(buf), however the same thing but using this.setCapacity("buf",bytes) and then tst(this.buf) just fail. I know I can fix it by passing pointer but it will require to edit most of my functions that I need to share with other projects.

Code: Select all

class _FFT
{
	buf := ""
	bufPtr := 0
	binsN := 0
	__new(){
		
	}
	
	resize(binsN){
		if(binsN>this.binsN){
			this.binsN := binsN
			bytes := binsN*2*8 ; binsN*CPLXsize*dataSize
			this.setCapacity("buf",bytes*2) ; 2 buffs at once
			this.bufPtr := this.getAddress("buf")
		}
	}
	fill(){
		loop,% this.binsN*4
			numPut(A_Index,this.bufPtr+0,(A_Index-1)*8,"double")
	}
	
	
	feedPtr(inputPtr,binsN){
		this.resize(binsN)
		this.fill()
		tst(this.buf) ; <----- it fails to pass buf
	}
}

tst(byref buf){
	str := ""
	loop, 10
		str .= numget(buf,(A_Index-1)*8,"double") "`n"
	msgbox,% str ; it should display numbers from 1 to 10
}
teadrinker
Posts: 1179
Joined: 29 Mar 2015, 09:41
Contact:

Re: class, this.setCapacity("buf",bytes) and passing buf as parameter

24 Sep 2019, 15:21

For me this code works:

Code: Select all

MyClass.CreateBuff()
MyClass.PassBuff()

class MyClass
{
   CreateBuff() {
      this.SetCapacity("buf", 4)
      NumPut(10, this.GetAddress("buf"), "UInt")
   }
   
   PassBuff() {
      MyFunc(this.buf)
   }
}

MyFunc(buf) {
   MsgBox, % NumGet(buf, "UInt")
}
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: class, this.setCapacity("buf",bytes) and passing buf as parameter

24 Sep 2019, 21:29

It is only first element, rest of buf is incerrect

Code: Select all

MyClass.CreateBuff()
MyClass.PassBuff()

class MyClass
{
   CreateBuff() {
      this.SetCapacity("buf", 4*10)
	 loop, 10
      NumPut(A_Index*10, this.GetAddress("buf"),(A_Index-1)*4, "UInt")
   }
   
   PassBuff() {
      MyFunc(this.buf)
   }
}

MyFunc(byref buf) {
	mem_display(&buf,0,10,"uint")
	MsgBox, % NumGet(buf, "UInt")
}

mem_display(memPtr,start,cnt,dataType="double"){
	static ds := {uchar:1,char:1,uschort:2,short:2,uint:4,int:4,float:4,double:8,int64:8}
	dataSize := ds[dataType]
	str := ""
	loop,% cnt
		str .= A_Index-1+start "`t" numGet(memPtr+(A_Index-1+start)*dataSize,dataType) "`n"
	msgbox,% str
}
teadrinker
Posts: 1179
Joined: 29 Mar 2015, 09:41
Contact:

Re: class, this.setCapacity("buf",bytes) and passing buf as parameter

24 Sep 2019, 22:01

Consider these variants:

Code: Select all

MyClass.CreateBuff()
MyClass.PassBuff()

class MyClass
{
   CreateBuff() {
      this.SetCapacity("buf", 4*10)
    loop, 10
      NumPut(A_Index*10, this.GetAddress("buf") + (A_Index-1)*4, "UInt")
   }
   
   PassBuff() {
      MyFunc(this, "buf")
   }
}

MyFunc(obj, key) {
   addr := obj.GetAddress(key)
   mem_display(addr,0,10,"uint")
}

mem_display(memPtr,start,cnt,dataType="double"){
   static ds := {uchar:1,char:1,uschort:2,short:2,uint:4,int:4,float:4,double:8,int64:8}
   dataSize := ds[dataType]
   str := ""
   loop,% cnt
      str .= A_Index-1+start "`t" numGet(memPtr+(A_Index-1+start)*dataSize,dataType) "`n"
   msgbox,% str
}
or

Code: Select all

MyClass.CreateBuff()
MyClass.PassBuff()

class MyClass
{
   CreateBuff() {
      this.SetCapacity("buf", 4*10)
    loop, 10
      NumPut(A_Index*10, this.GetAddress("buf") + (A_Index-1)*4, "UInt")
   }
   
   PassBuff() {
      MyFunc("buf")
   }
}

MyFunc(key) {
   addr := MyClass.GetAddress(key)
   mem_display(addr,0,10,"uint")
}

mem_display(memPtr,start,cnt,dataType="double"){
   static ds := {uchar:1,char:1,uschort:2,short:2,uint:4,int:4,float:4,double:8,int64:8}
   dataSize := ds[dataType]
   str := ""
   loop,% cnt
      str .= A_Index-1+start "`t" numGet(memPtr+(A_Index-1+start)*dataSize,dataType) "`n"
   msgbox,% str
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], blue83 and 255 guests