November 29, 2020, 03:49:32 PM

Author Topic: Memory location value read  (Read 1098 times)

Offline biggy60

  • Jr. Member
  • **
  • Posts: 2
Memory location value read
« on: March 19, 2018, 02:16:31 AM »
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?

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1077
Re: Memory location value read
« Reply #1 on: March 19, 2018, 07:26:27 AM »
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 :
Code: [Select]
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"
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline biggy60

  • Jr. Member
  • **
  • Posts: 2
Re: Memory location value read
« Reply #2 on: March 19, 2018, 10:18:07 AM »
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

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1077
Re: Memory location value read
« Reply #3 on: March 19, 2018, 03:59:58 PM »
"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)
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal