braydenanderson2014 / C-Arduino-Libraries

This repository contains C++ and Arduino Libraries that are lightweight and easy to use. All libraries were created/mimicked by me and chatgpt.
Apache License 2.0
13 stars 0 forks source link

Storing Strings (ARRAYLIST) #76

Closed piscodev closed 5 months ago

piscodev commented 5 months ago

I have RFID tag scanner, 8 tags on hand, and I store the Strings that are scanned to the <Dynamic list then iterate the list to print out what's inside, however,

After sometime, I just noticed unrecognized strings inside the list, I dont know if its the dynamic size thats causing the bug, or the scanner. Actually, the scanner outputs the string as HEX, and I just converted it to string and it printed fine on Serial Monitor, but not when stored on list.

Here's the logs of the scanned tags:

From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 8 From List: � 68940000502B39F5B4E8 [#3] Size: 8 From List: From List: � 689400005 [#4] Size: 8 From List: � 6894$����� 6894 [#5] Size: 8 From List: E28068940000502B39F5A0E8 [#6] Size: 8 From List: E28068940000502B39F5A0E8 [#7] Size: 8 From List: E28068940000402B39F5C4E8 [#0] Size: 9 From List: E280<From List: E2806 [#1] Size: 9 From List: E28068940000502B39F59CE8 [#2] Size: 9 From List: � 68940000502B39F5B4E8 [#3] Size: 9 From List: From List: E2806$���� [#4] Size: 9 From List: t: ($����E2806894 [#5] Size: 9 From List: E28068940000502B39F5A0E8 [#6] Size: 9 From List: E28068940000502B39F5A0E8 [#7] Size: 9 From List: E28068940000402B39F5A4E8 [#8] Size: 9 From List: Size: \� From Lis [#0] Size: 10 From List: E280<From List: E2806 [#1] Size: 10 From List: E28068940000502B39F59CE8 [#2] Size: 10 From List: � 68940000502B39F5B4E8 [#3] Size: 10 From List: From List: E2806$���� [#4] Size: 10 From List: t: ($����E2806894 [#5] Size: 10 From List: E28068940000502B39F5A0E8 [#6] Size: 10 From List: E28068940000502B39F5A0E8 [#7] Size: 10 From List: E28068940000402B39F5A4E8 [#8] Size: 10 From List: E28068940000502B39F5ACE8 [#9] Size: 10 From List: CE8 [#9] Size: 10omP [#0] Size: 10 From List: E280<From List: E2806 [#1] Size: 10 From List: E28068940000502B39F59CE8 [#2] Size: 10 From List: � 68940000502B39F5B4E8 [#3] Size: 10 From List: From List: E2806$���� [#4] Size: 10 From List: t: ($����E2806894 [#5] Size: 10 From List: E28068940000502B39F5A0E8 [#6] Size: 10 From List: E28068940000502B39F5A0E8 [#7] Size: 10 From List: E28068940000402B39F5A4E8 [#8] Size: 10 From List: E28068940000502B39F5ACE8 [#9] Size: 10

braydenanderson2014 commented 5 months ago

Thank you for reporting the issue... I will research the issue and get back to you. For now though I will be transferring your issue to the main repository for easier issue tracking. Thank you!

braydenanderson2014 commented 5 months ago

Just for research purposes, how are you iterating over the list? Are you using a for loop with List.get(I) or List.getAsString(i)… OR are you creating an iterator object and using that to iterate over the list?

braydenanderson2014 commented 5 months ago

Just for research purposes, how are you iterating over the list? Are you using a for loop with List.get(I) or List.getAsString(i)… OR are you creating an iterator object and using that to iterate over the list? If you have an sd card reader with the arduino you could also try using the SDList library instead. It used ArrayList in the background but has the ability to save everything to a file and load it back in which may assist in keeping everything valid... I can't guarantee it will work since it does use the ArrayList library in the background and it's not as performant since it saves and loads from a file but this might be a work around. In the mean time I will research the issue as soon as I am able.

piscodev commented 5 months ago
Using the ::FIXED seems to work fine at 500, but when in ::DYNAMIC 100+, random characters starts showing when I get 5+ or randomly strings on the list.Im sending the tags to MongoDB, things worked fine. Only the ::Dynamic was the issue. Thanks.From: Brayden AndersonSent: Saturday, May 25, 2024 3:00 PMTo: braydenanderson2014/C-Arduino-LibrariesCc: Piscode; AuthorSubject: Re: [braydenanderson2014/C-Arduino-Libraries] Storing Strings (ARRAYLIST) (Issue #76) Just for research purposes, how are you iterating over the list? Are you using a for loop with List.get(I) or List.getAsString(i)… OR are you creating an iterator object and using that to iterate over the list? If you have an sd card reader with the arduino you could also try using the SDList library instead. It used ArrayList in the background but has the ability to save everything to a file and load it back in which may assist in keeping everything valid... I can't guarantee it will work since it does use the ArrayList library in the background and it's not as performant since it saves and loads from a file but this might be a work around. In the mean time I will research the issue as soon as I am able.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>  ---DISCLAIMER AND CONFIDENTIALITY NOTICE The Mindanao State University-Iligan Institute of Technology (MSU-IIT) makes no warranties of any kind, whether expressed or implied, with respect to the MSU-IIT e-mail resources it provides. MSU-IIT will not be responsible for damages resulting from the use of MSU-IIT e-mail resources, including, but not limited to, loss of data resulting from delays, non-deliveries, missed deliveries, service interruptions caused by the negligence of a MSU-IIT employee, or by the User's error or omissions. MSU-IIT specifically denies any responsibility for the accuracy or quality of information obtained through MSU-IIT e-mail resources, except material represented as an official MSU-IIT record. Any views expressed in this e-mail are those of the individual sender and may not necessarily reflect the views of MSU-IIT, except where the message states otherwise and the sender is authorized to state them to be the views of MSU-IIT. The information contained in this e-mail, including those in its attachments, is confidential and intended only for the person(s) or entity(ies) to which it is addressed. If you are not an intended recipient, you must not read, copy, store, disclose, distribute this message, or act in reliance upon the information contained in it. If you received this e-mail in error, please contact the sender and delete the material from any computer or system.
braydenanderson2014 commented 5 months ago

Sounds like it could be an issue with the resize function. With 8 tags in the list that is the perfect amount of items to resize. What arduino are you using to run the ArrayList?

piscodev commented 5 months ago
Most likely. Probably each incoming bytes did not went to certain memory location and cause it to overflow.Arduino UNO R4 WiFi From: Brayden AndersonSent: Saturday, May 25, 2024 3:14 PMTo: braydenanderson2014/C-Arduino-LibrariesCc: Piscode; AuthorSubject: Re: [braydenanderson2014/C-Arduino-Libraries] Storing Strings (ARRAYLIST) (Issue #76) Sounds like it could be an issue with the resize function. With 8 tags in the list that is the perfect amount of items to resize. What arduino are you using to run the ArrayList?—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>  ---DISCLAIMER AND CONFIDENTIALITY NOTICE The Mindanao State University-Iligan Institute of Technology (MSU-IIT) makes no warranties of any kind, whether expressed or implied, with respect to the MSU-IIT e-mail resources it provides. MSU-IIT will not be responsible for damages resulting from the use of MSU-IIT e-mail resources, including, but not limited to, loss of data resulting from delays, non-deliveries, missed deliveries, service interruptions caused by the negligence of a MSU-IIT employee, or by the User's error or omissions. MSU-IIT specifically denies any responsibility for the accuracy or quality of information obtained through MSU-IIT e-mail resources, except material represented as an official MSU-IIT record. Any views expressed in this e-mail are those of the individual sender and may not necessarily reflect the views of MSU-IIT, except where the message states otherwise and the sender is authorized to state them to be the views of MSU-IIT. The information contained in this e-mail, including those in its attachments, is confidential and intended only for the person(s) or entity(ies) to which it is addressed. If you are not an intended recipient, you must not read, copy, store, disclose, distribute this message, or act in reliance upon the information contained in it. If you received this e-mail in error, please contact the sender and delete the material from any computer or system.
braydenanderson2014 commented 5 months ago

Ok sounds good. I'll take a look as soon as I am able.

piscodev commented 5 months ago
 I liked the library . Alright, thanks! From: Brayden AndersonSent: Saturday, May 25, 2024 3:18 PMTo: braydenanderson2014/C-Arduino-LibrariesCc: Piscode; AuthorSubject: Re: [braydenanderson2014/C-Arduino-Libraries] Storing Strings (ARRAYLIST) (Issue #76) Ok sounds good. I'll take a look as soon as I am able.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>  ---DISCLAIMER AND CONFIDENTIALITY NOTICE The Mindanao State University-Iligan Institute of Technology (MSU-IIT) makes no warranties of any kind, whether expressed or implied, with respect to the MSU-IIT e-mail resources it provides. MSU-IIT will not be responsible for damages resulting from the use of MSU-IIT e-mail resources, including, but not limited to, loss of data resulting from delays, non-deliveries, missed deliveries, service interruptions caused by the negligence of a MSU-IIT employee, or by the User's error or omissions. MSU-IIT specifically denies any responsibility for the accuracy or quality of information obtained through MSU-IIT e-mail resources, except material represented as an official MSU-IIT record. Any views expressed in this e-mail are those of the individual sender and may not necessarily reflect the views of MSU-IIT, except where the message states otherwise and the sender is authorized to state them to be the views of MSU-IIT. The information contained in this e-mail, including those in its attachments, is confidential and intended only for the person(s) or entity(ies) to which it is addressed. If you are not an intended recipient, you must not read, copy, store, disclose, distribute this message, or act in reliance upon the information contained in it. If you received this e-mail in error, please contact the sender and delete the material from any computer or system.
braydenanderson2014 commented 5 months ago

This issue has been confirmed and patched. The issue was indeed with the way the resize function was copying the data. It was using memcpy. The patch will introduce a new resize2() function and a new DYNAMIC2 option. By default, DYNAMIC2 will now be the default resize function used unless specified. The options will be { FIXED, DYNAMIC, DYNAMIC2 }. The new resize function is a bit goofy in that it will use a forloop and loop through each item in the old array and add it to the new. The original resize function made use of memcpy function instead which seems to be a bit unpredictable with strings.

Here is the test code i used. (I am using the patched Version of ArrayList that will be under the Development Branch. It will be published shortly to Platformio and Arduino Library Manager.

#include <Arduino.h>
#include <ArrayList.h>

ArrayList<String> list;
unsigned long lastMillis = 0;
void setup(){
    Serial.begin(9600);
    while(!Serial);
    delay(5000);
    list.add("1234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 0: " + list.get(0));
    delay(1000);

    list.add("2234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 1: " + list.get(1));
    delay(1000);

    list.add("3234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 2: " + list.get(2));
    delay(1000);

    list.add("4234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 3: " + list.get(3));
    delay(1000);

    list.add("5234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 4: " + list.get(4));
    delay(1000);

    list.add("6234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 5: " + list.get(5));
    delay(1000);

    list.add("7234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 6: " + list.get(6));
    delay(1000);

    list.add("8234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 7: " + list.get(7));
    delay(1000);

    list.add("9234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 8: " + list.get(8));
    delay(1000);

    list.add("A234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 9: " + list.get(9));
    delay(1000);

    list.add("B234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 10: " + list.get(10));
    delay(1000);

    list.add("C234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 11: " + list.get(11));
    delay(1000);

    list.add("D234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 12: " + list.get(12));
    delay(1000);

    list.add("E234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 13: " + list.get(13));
    delay(1000);

    list.add("F234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 14: " + list.get(14));
    delay(1000);

    list.add("G234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 15: " + list.get(15));
    delay(1000);

    list.add("H234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 16: " + list.get(16));
    delay(1000);

    list.add("I234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 17: " + list.get(17));
    delay(1000);

    list.add("J234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 18: " + list.get(18));
    delay(1000);

    list.add("K234567890ABCDEF12345678");
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
    Serial.println("Element at index 19: " + list.get(19));
    delay(1000);

    Serial.println("Removing Now Printing");
    for(int i = 0; i < list.size(); i++){
        Serial.println(list.get(i));
    }
    Serial.println("Size: " + String(list.size()));
    Serial.println("Capacity: " + String(list.capacity()));
}

void loop(){

}