How to create static var inside class that is separate from any other initialized object? Topic is solved

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

How to create static var inside class that is separate from any other initialized object?

Post by smarq8 » 12 Aug 2018, 13:21

So i am currenty writing class for Serial communication. Until now i use only one FIFO buffer for rx and everything work fine, but now i need to add tx buffer and here begin my problem because for rx and tx share same memory space (bot buffer has the same address). So is it possible to make buffer separate from each other? I know i can declare static buffers outside FIFO class and pass as ByRef parameter but I am wonder can I do everything inside my FIFO class?
By the way I am also wonder can I be sure that address of any buffer never change during executing script?

Code: Select all

Serial := new _serial()
return

class _serial
{
	
	__new()
	{
		RX := new FIFO(1024)
		TX := new FIFO(1024)
		msgbox,% RX.adr "`n" TX.adr	
	}
	
}


class FIFO
{
	adr := 0
	size := 0
	__new(_size){
		static buf ; <---------- How to create separate buffer for each new?
		VarSetCapacity(buf, _size, 0)
		this.size := _size
		this.adr  := &buf
	}
	
}
Helgef
Posts: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to create static var inside class that is separate from any other initialized object?  Topic is solved

Post by Helgef » 12 Aug 2018, 13:35

Code: Select all

this.setcapacity("buf", _size)
this.adr := this.getaddress("buf")
It doesn't initialise the memory to zero though.

Cheers.
smarq8
Posts: 51
Joined: 16 Jan 2016, 00:33

Re: How to create static var inside class that is separate from any other initialized object?

Post by smarq8 » 12 Aug 2018, 13:48

Thanks, it probably does work fine now.

Code: Select all

Serial := new _serial()
return

class _serial
{
	
	__new()
	{
		RX := new FIFO(1024*128)
		TX := new FIFO(1024*128)
		msgbox,% RX.adr "`n" TX.adr	
	}
	
}


class FIFO
{
	buf := ""
	adr := 0
	size := 0
	__new(_size){
		;static buf ; <---------- How to create separate buffer for each new?
		;VarSetCapacity(buf, _size, 0)
		;this.size := _size
		;this.adr  := &buf
		this.SetCapacity("buf", _size)
		this.size := _size
		this.adr  := this.getaddress("buf")
	}
	
}
Post Reply

Return to “Ask For Help”