B4J Question Is that the best way to count bytes of an object (List) ?

Magma

Expert
Licensed User
Longtime User
Hi there...

Is that the best way (fastest) to count bytes of an object (List) ?

Dim list1 As List
list1.Initialize

Dim Ser As B4XSerializator

Dim map1 As Map 'add some things into list....
map1.Initialize
map1.Put("HELP","123123")
list1.Add("test1")
list1.Add(map1)

Dim bb() As Byte= Ser.ConvertObjectToBytes(list1)

Log(bb.Length)

ps: I am asking... because is somehow silly to create a "bb() as byte" - that will eat some memory - to count something else...
 

DonManfred

Expert
Licensed User
Longtime User
What is the reason to count anything on such a list?
You are mixing single strings with Maps inside one list. That makes no sense to me.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
What is the reason to count anything on such a list?
Well, in a new app will have history (undo-redo)... with many lists/maps/and string with jsons into one list (that will be the history array) and wanna limit the steps (thought having 99 steps of undo) of undo-redo... but first wanna count the bytes... may be keep the calculations of bytes - if the app running at PCs with low specs...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Is it working with timer tick
It would work with a timer tick, but it may not give you the experience that undo usually does.It will depend largely on what your app is doing. It would be simple to implement using a timer tick, so try it and see if it works for you.

I've always driven it from an event, button clicks, menu selections etc. For text, I normally add a keypressed filter and update the undomanager after a preset number of keystrokes or seconds, whichever comes first. That does use a timer, but only starts when a key is pressed after the last timeout.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
It depends on the specific app requirements. For a text editor as an example, it doesn't make sense to create a new state for every key typed and a timer that checks for changes is more appropriate.
is for our B4XDesigner... so will have controls moving... delete them, copy, paste, textfields... etc
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
As for your original question (uses ByteConverter)
B4X:
    ' needs /2 as 0x34 becomes 0x33 0x34
    Log(bc.HexFromBytes(Ser.ConvertObjectToBytes(list1)).Length/2)

Not really useful, but the question was fun.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
As for your original question (uses ByteConverter)
B4X:
    ' needs /2 as 0x34 becomes 0x33 0x34
    Log(bc.HexFromBytes(Ser.ConvertObjectToBytes(list1)).Length/2)

Not really useful, but the question was fun.
Is actually different thing.. 4 things

1.convert list to bytes
2.bytes to hex
3.getting length of hex string object
4.divide by 2
 
Upvote 0
Top