Memory location value read

Started by biggy60, March 19, 2018, 02:16:31

Previous topic - Next topic

biggy60

Hi;
a statistical program generates, at each request, an integer in a different memory location each time the program is started. With other software I am able to identify and display the value stored in this location, but its variation should be quickly detected by a simple BB program so that I can work quickly according to the value detected. I know the existence of the BB peek function, but I do not understand how to tell the program the required memory location (but maybe it's better to use an API decls.) Can anyone help me?

RemiD

#1
Here is an old example that i have made to show how to write / read in a customtype list, in a dim array list, in a bank list :

Graphics3D(640,480,32,2)

nMax% = 100000

;initialize the custom type list :
Type Ent
Field Var%
End Type
For n% = 1 To nMax
e.Ent = New Ent
Next

;initialize the dim array list :
Global EntsCount% = 0
Dim EntVar%(nMax)
For n% = 1 To nMax
EntsCount = EntsCount + 1
I% = EntsCount
Next

;initialize the bank list :
BankEntVarSize% = nMax*1 ; 1 corresponds to the size of a byte, for a short it would be 2, for an integer it would be 4, for a float it would be 4...
BankEntVar = CreateBank(BankEntVarSize)

Print("")
;Write a value of an instance of the custom type
MilliStart% = MilliSecs()
For e.Ent = Each Ent
e\Var = Rand(0,255)
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to write (integers) in a custom type")

;Read in a value of an instance of the custom type
MilliStart% = MilliSecs()
For e.Ent = Each Ent
TVar# = e\Var
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to read (integers) in a custom type")

Print("")
;Write a value of the Dim Array list
MilliStart% = MilliSecs()
For I% = 1 To EntsCount Step 1
EntVar(I) = Rand(0,255)
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to write (integers) in a dim array")

;Read a value of the Dim Array list
MilliStart% = MilliSecs()
For I% = 1 To EntsCount Step 1
TVar# = EntVar(I)
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to read (integers) in a dim array")

Print("")
;Write a value of the Bank list
MilliStart% = MilliSecs()
For o% = 0 To BankEntVarSize-1 Step 1
PokeByte(BankEntVar,o,Rand(0,255))
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to write (bytes) in a bank")

;Read a value of the Bank list
MilliStart% = MilliSecs()
For o% = 0 To BankEntVarSize-1 Step 1
TVar# = PeekByte(BankEntVar,o)
Next
MilliTime% = MilliSecs() - MilliStart
Print(MilliTime+"ms to read (bytes) in a bank")

FlushKeys()
WaitKey()


Maybe this can help you understand how to write / read in a "memory bank"

biggy60

Hi, RemiD, tnx for quick reply.
I understand that rMax% is the address of the last testable memory location (but 100,000 intended as a decimal or hexadecimal?); I have to check the value contained in a single known memory location (example format: 3152BA20), so I do not need an array so big ... The code seems clear to me, as soon as I have some time I try it.
Thank you

RemiD

#3
"nMax" just means "max number of instances in a list". (because i did some tests in the past, to see if i could store some datas in a memory bank (bytes) instead of in a dim array (integers))

This code is not exactly what you want, but it shows how to write / read a type of value (byte, short, integer, float) in a memory bank.

from the Blitz3d documentation ;
Quote
The bank commands allow you to perform high-speed data operations on a block of memory. This is useful for writing your own compression/decompression routines, passing and receiving data to and from a DLL and more. Banks start at 0 and finish at size-1.

The data types available for use with a bank are:

Byte - takes up one byte. Values can be in the range 0 to 255.
Short - takes up two bytes. Values can be in the range 0 to 65535.
Int - takes up four bytes. Values can be in the range -2147483647 to 2147483647.
Float - takes up four bytes.

Apparently you can write / read different types of values (byte, short, integer, float) in a memory bank, like in a binary file, but you have to know where to read (the offset) and what is read (the type of value)