B4J Question Compare Array of Objects

Blueforcer

Well-Known Member
Licensed User
Longtime User
I get an array of objects from a function.
But since the same array comes several times in a row (every 80ms) I want to discard the following one to save computing time.
How can I compare this array fast if the length of the array and the content can be different?

p.s the objectarrays are in a list. so normally i have to compare the list with the list send before. But as i read i have to compare the content
Unbenannt.PNG

is it possible to create a hash from this list and only compare the hash?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
It is surprising how quick iterating lists can be. A while back I tried a test comparing iterating the list and hashing the same list. The test is attached if you want to try it yourself.

If obviously depends what the content of the objects are, but it's a place to start.

Note: it was comparing objects, not the objects content.
 

Attachments

  • ListHashTest.zip
    2.4 KB · Views: 211
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Thanks i will have a look at it.
Hashing dont work, its always a different value, even its the exact same list with arrays of objects. I think its caused by the different memory allocation?
I will try to iterating the lists now, what i think could be tricky because i dont know whats inside.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Here is something I worked on a long time ago that does exactly that. It could be optimised for your purpose, as it can compare most objects and content, classes and types as well if you provide the comparison methods.

I found it a little slow as it is a complete tool and ended up writing specific comparisons as needed, but all the required code is in there.
 

Attachments

  • CloneCompareObjects.zip
    9 KB · Views: 220
Last edited:
Upvote 0
Top