Memory_Compare/Memory_Differs/Memory_IsEqual change the syntax for 1 please
issueid=640 28-02-2021 17:24
thinBasic MVPs
Number of reported issues by ReneMiner: 83
Memory_Compare/Memory_Differs/Memory_IsEqual change the syntax for 1 please
The functions do nearly the same - but we need another one!

i copy it from the help:

the difference: it returns TRUE/FALSE.
My Suggestions change nothing in compatibility if one of the 3 functions can have the ability to accept an optional string-parameter and another one would accept
an additional numeric parameter. Just remind yourself what they do:



Compare two memory areas checking if they contain the exact same bytes.


lResult = Memory_Compare(pMem1, pMem2, Size)


Zero: means the two memory areas are the same
A number: the first byte where the two memory areas start to differ


Name Type Optional Meaning
pMem1 Numeric No A valid 32-bit memory address
pMem2 Numeric No A valid 32-bit memory address
Size Numeric Yes A numeric expression that specifies the number of consecutive bytes to check

lets say we gave Memory_Compare a second, optional size-parameter,
assume it had it all the time and it was equal always with the first one.

Result = Memory_Compare pMem1, pMem2, Size1[,optional Size2]

Example 1 : Size1 > Size2, i use an odd number on purpose

Memory_Compare( 123456, 987654, 1000, 42 )

local Result as number
local Mem2Bytes(42) As Byte At 987654 ' thats what we search for. a sequence of 42 bytes
local Mem2$ As String * 42 At 987654 ' time to virtualize absolute fixed-size strings to be interpreted as bytes? No. Do not call them String!

Thus antique relicts of odd sized data in Memory have nothing in common with smart and fast, dynamic strings. Strings are to store documents, letters, books and even the bible.
These String*42 things are from a time when programmers experienced a switch from homecomputers to PCs and were used to have strings limited to 32 or 64 Bytes on their Ataris, Commodores , ZX's and ti81's. They squeezed the strings full with bytes and sent them via modem and except for the last string it was not necessary to tell anyone the size of the data packages. They had to use strings because there were no other data types. but today a 128 bit variable -16 bytes- is thinkeable and there is more ahead. we use still ascii (utf-7 or -8) and a memory-unit can hold already 8 charrs including numbers and punctuation.
we all know 128 bit will come, and then 256 bit. and so on. we will need to cut down the native variables soon, all below quad are variables smaller already than a memory-unit can poke in and the remaining part of memory is filled less than half when the computers will complain Memory-Overflow-Errors. we need something that gives us back the flexibility. Float80 is a good start. Get away from the divideable by 2-cramp in the users brains and downgrade the String*42 to become

local Mem2 As SequenceOf(Byte, 42)

the 42-element-array becomes a sequence:

' not virtually:
_!() As Byte ' subelement has no name that users could access

' on create the udt will beg thincore to redim his subelements array:

Function _Create(Typename, count)
Redim Me._!(count/SizeOf(Typename))
End Function

Function _Destroy()
Reset Me._!
End Function
End Type

and back to topic>>we dim as another known variable using its name - now virtually

local mem1( Size1 \ sizeOf(Mem2) ) As Mem2 At 123456
number remaining = size1 - sizeOf(mem1)
different = Array Scan Mem1, <> Mem2
if different then
' call recursive with 3 parameters
result = 123456 +(different-1) * Size2 + Memory_Compare(GetAt(Mem1(different)), 987654, Size2)
elseif remaining then
result= memory_compare(GetAt(Mem1(Ubound(Mem1))))+ Size2, 987654, remaining)
if result then result += 123456 + size1 - remaining
return result

when size2 > size1 then it will just swap( pMem1, pMem2) and swap(size1, size2)

- Actually i was looking for a function if a string ( some area in memory) consists of all 0. Thats why i had the idea but all the memory-comparison functions assume same sized areas to compare. And PeekZ$ would tell me its not all 0 but it will also stop as soon a zero is encountered. Now if Memory_Differs could accept an additional parameter - or better, thincore would know if a string is inviolved then the second parameter will be size ofpMem1 and the 3rd parameter (dynamic string) carries its size in front of its pointer. Exceptional if "" the memory of 1000 bytes differs in the first byte already from nothing.



Compare two memory areas checking if they contain the exact same bytes.


lResult = Memory_Differs(pMem1, pMem2, Size)

lResult =Memory_Differs(pMem1, Size, StringExpression)

it returns - as Memory_isEqual - True or False

And if you manage it - what you think? Time for overloading? - Same named functions that accept different parameter-count and types - as
Function f( Overload ) As Long  
' you come with a parameter? try the next f()!
End Function

Function f(Byref bParam As  Byte, optional byVal sParam as String, Overload) As Long
' what you have a byref string and a byval byte in your luggage?
' nay wrong order i will not take it, try downstairs
End Function

function f(Byref sParam as String, Byref lParam As Long, optional byval bParam As Byte, Overload)
' byref string and byval byte you got? the long is mandatory, sorry
' good luck further down!
End Function

function f(Byref sParam as String, Byref lParam As Long, byref qParam as QWord, optional byval bParam As Byte)
' byref string and byval byte you got? the long and the QWord are mandatory. 
'i have to send you back home with an error. i will not fork you further down.
End Function
Issue Details
Issue Number 640
Issue Type Feature
Project thinBasic
Category Core engine (thinCore.dll)
Status Suggested
Priority Unknown
Suggested Version 2.0
Implemented Version (none)
Milestone (none)
Votes for this feature 0
Votes against this feature 0
Assigned Users (none)
Tags (none)

+ Reply