From your for loop syntax, it's clear you're using C++ and not C. That being the case, I'm not clear why you're using malloc/free and managing memory directly yourself. The C++ Standard Library has very suitable improvements in this area.
Having said that, your AddPair algorithm is something like:
1. Ensure the arrays are large enough for the new pair
2. Append the new pair
When I try and compile this using the arduino IDE it complains about map... which is why I wanted to write my own.
I am trying to get my head around char arrays and 2 dimensional arrays in c++... so if the code I wrote can be rewritten WIHTOUT the malloc lines, how would I do that, please? If you have time?
the arduino IDE it complains about map... which is why I wanted to write my own.
Don't do that. You need to fix the environment first. std::map is part of the C++ standard library. It really should be available. Does Arduino explicitly disallow STL?
You can't manage a structure that grows dynamically without using the heap. You either need to use malloc/free or new/delete.
An alternative is to use a fixed length structure that has a fixed upper limit.
Is the malloc/free restriction related to the embedded environment?
Just out of curiosity... I am trying to understand why I am getting a null exception (in the function in my original post) when ArrayLength is 2. It seems to be something to do with their being multiple previous values to move to the new array.
Looking at the original function I posted... I get an error on the loop that populates previous key/values.
1 2 3 4 5
for (int i = 0; i < *ArrayLength; i++)
{
tmpKeys[i] = *KeyArray[i];
tmpValues[i] = *ValueArray[i]; // <<<--- error occurs here first
}
I get the null error "object reference not set to an instance of an object". The weird thing is, when I step it through I don't see where the null is coming from.
Both tmpValues[i] and *ValueArray[i] have a value so wheres the null? I am a VB programmer so if there is something wrong that is c++ specific please let me know so I can try and understand it.