array vs string for Active Ram storage

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

array vs string for Active Ram storage

Post by Hellbent » 25 Sep 2021, 13:50

I need to store potentially millions of Time|Value pairs and the simplest way to use that data would be to have it in this form

Code: Select all


obj := { Time: Value }

;or less ideal 

arr[ Index ] := "Time|Value"

But my suspicion is that it would require a fair bit more ram than if I went with something like this.

Code: Select all

string .= "Time|Value" ";"
I shouldn't have any issues using the first method right?

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

Re: array vs string for Active Ram storage

Post by swagfag » 25 Sep 2021, 14:29

it would require an additional 16/32 bytes per element

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: array vs string for Active Ram storage

Post by Hellbent » 25 Sep 2021, 14:41

swagfag wrote:
25 Sep 2021, 14:29
it would require an additional 16/32 bytes per element
Ok great.
Any reason you can think of to not to go with { key : value } besides the extra memory use?

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: array vs string for Active Ram storage

Post by mikeyww » 25 Sep 2021, 14:41

The following script ran without error.

Code: Select all

obj := {}, n := 2000000, tip := 250, i := 0, start := A_TickCount
Loop, %n% {
 last := obj[A_Now ++i] := A_Index * 1.5
 If (A_Index / tip = A_Index // tip)
  ToolTip, %A_Index%, 300, 300
}
SoundBeep, 1000
ToolTip
MsgBox, 64, Last item (n=%n%), % last "`nElapsed: " (A_TickCount - start) / 1000 " seconds"
Output:

image210925-1541-001.png
image210925-1541-001.png (9.31 KiB) Viewed 659 times

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

Re: array vs string for Active Ram storage

Post by swagfag » 25 Sep 2021, 14:49

Hellbent wrote:
25 Sep 2021, 14:41
swagfag wrote:
25 Sep 2021, 14:29
it would require an additional 16/32 bytes per element
Ok great.
Any reason you can think of to not to go with { key : value } besides the extra memory use?
unless u explain what ur concerns and intentions are, i cant say anything

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: array vs string for Active Ram storage

Post by Hellbent » 25 Sep 2021, 14:50

mikeyww wrote:
25 Sep 2021, 14:41
The following script ran without error.

Code: Select all

obj := {}, n := 2000000, tip := 250, i := 0, start := A_TickCount
Loop, %n% {
 last := obj[A_Now ++i] := A_Index * 1.5
 If (A_Index / tip = A_Index // tip)
  ToolTip, %A_Index%, 300, 300
}
SoundBeep, 1000
ToolTip
MsgBox, 64, Last item (n=%n%), % last "`nElapsed: " (A_TickCount - start) / 1000 " seconds"
Output:


image210925-1541-001.png
Thank you. I had caught your last post. P.S yes it worked.


The new one took 56 seconds. The first one is still going.

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: array vs string for Active Ram storage

Post by Hellbent » 25 Sep 2021, 14:58

@swagfag

I intend to record every time a click is made and store it in a structure that will allow me to manipulate how the data is interpreted / displayed.

.
Image
.

I don't have the exact structure nailed down yet but it will work something like this.

Code: Select all

#If ( Active )

~$*LButton::
	if( CurrentMin != A_Min ){ 			;if it is a new min create a new array to record the clicks in that min.
		CurrentMin := A_Min
		Clicks[ CurrentMin ] := []
	}
	Clicks[ CurrentMin ].Push( A_Sec )   ;Push a timestamp of the second the click happend.
	return

#If


With that I should be able to select a time frame and display it, as well as switching between time scales.

As you can see the structure in the code box would only work for an hour before it would overwrite itself, so I still have to work all that out.

As for concerns. Just looking out for any pitfalls that I might not be aware of.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: array vs string for Active Ram storage

Post by mikeyww » 25 Sep 2021, 17:02

I imagine that you just need something like this.

Code: Select all

Clicks := []
~*LButton::Clicks[A_Now] := (0 Clicks[A_Now]) + 1

F3::
start := Clicks.Count(), Clicks := purge(Clicks, 20210925192835)
MsgBox, 64, Purged, % start " -> " Clicks.Count()
Return

purge(Clicks, minTime) {
 minTime += -1, S
 Clicks.Delete(20200101000000, minTime)
 Return Clicks
}

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: array vs string for Active Ram storage

Post by Hellbent » 25 Sep 2021, 18:44

mikeyww wrote:
25 Sep 2021, 17:02
You can always remove items easily enough.
I have decided to go beyond just making a demo with it. The code from the other thread was mainly for a simple demo of some sort of graphing
on a layered window, and it does that well enough. I just have to add in the other graph styles to it.
Working on the demo got me wanting to do something a bit more involved and challenging with it. I don't know how far I'll get with it but I'm sure I'll pick up some new tricks.


I imagine that you just need something like this.

Code: Select all

Clicks := []
~*LButton::Clicks[A_Now] := (0 Clicks[A_Now]) + 1
That looks good, I'm rather lacking in my time manipulation skills. How would you go about tapping into that stream at these points.

1.
Assuming you wanted to switch to displaying the CURRENT 1 or 2 mins how would you connect to the display array ( the bins for the graphics see codebox )
In this case the display array value is the number of clicks that were recorded in the second it is representing.
each bin is the the data for the bars, they stay in the same position but the data sweeps across them as time passes.
The first bin would need to be the last full second recorded

Code: Select all


;This needs connecting to the stream
Obj.Display := [] ; x amount get initialized ( 1 or 2 mins ) 

;******
;******
;add stuff to the display array
;******
;******

DrawStuff() ;not related. 


2.
Assuming this had a bunch of sliders and buttons and you were able to switch to showing cpm for 1-2 hours of your choosing , how would you go about tapping into the data and fill the display bins with the correct amounts?


Thanks

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: array vs string for Active Ram storage

Post by mikeyww » 25 Sep 2021, 18:47

You can find the min and max time, and then loop through the data to get the values that you need. An alternative is that you can clone the array, delete the values you don't need, and use what is left.

Code: Select all

Clicks := []
~*LButton::Clicks[now := A_Now] := (0 Clicks[now]) + 1    ; Store the cps for this time

F3::range := keep(Clicks, 20210926074000, 20210926074005) ; Keep only the range of times indicated

keep(Clicks, minTime, maxTime := False) {                 ; Discard times outside the range indicated
 ; A null maxTime will discard only times before minTime
 range := Clicks.Clone()
 minTime += -1, S                                         ; Subtract one second
 range.Delete(0, minTime)                                 ; Delete times earlier than the minTime
 If maxTime {                                             ; If maxTime was specified,
  maxTime += 1, S                                         ;  then add one second,
  range.Delete(maxTime, 21000101000000)                   ;  and delete times later than the maxTime
 }
 MsgBox, 64, Change in count                              ; Show the change in count of array elements
         , % Clicks.Count() " -> " range.Count() 
 Return range
}

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: array vs string for Active Ram storage

Post by Hellbent » 27 Sep 2021, 08:28

mikeyww wrote:
25 Sep 2021, 18:47
You can find the min and max time, and then loop through the data to get the values that you need. An alternative is that you can clone the array, delete the values you don't need, and use what is left.
Thanks. I played around with adjusting time and I have a decent grasp now.
Temp (1).gif
Temp (1).gif (84.69 KiB) Viewed 489 times
Spoiler
I do however have a few questions.

1. How do you cycle months and years?
I looked up sysget like you had pointed to but you can guess what I found ( I can see it was just a simple slip up )

2. How do you select a hour/min/sec etc.
How do you go about inserting a hour (or w/e) instead of incrementing?

Thanks

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: array vs string for Active Ram storage

Post by mikeyww » 27 Sep 2021, 09:02

You can use SubStr to read or write any element of a timestamp, or use FormatTime, but adjusting the month requires arbitrary decisions about how to handle changes to invalid days. Examples of approaches to incrementing the month are posted on the forum.

Post Reply

Return to “Ask for Help (v1)”