My someFunction calls another function that builds a char* randomly character by character with no term \0... not sure how i would apply the string or vector to this algorithm...
any insight would be greatly appreciated...
thanks.
edit: are you suggesting using a vector<char*> vs the char**?
What do you mean it builds it character by character? Do you keep reallocating space for new characters? std::string does this for you.
If you come from Java, realize that C++ has no garbage collection, so anything allocated with NEW has to be DELETEed.
Because of the above, and many other problems, try to avoid raw pointers as much as possible. Use containers like vector, which handle allocation and deletion internally.
Don't use global variables.
And your problem is probably that your randomization function isn't actually random.
I understand the garbage collection vs freeing the memory in code...and the pseudorandom character generation works adequately for my purpose...the char* that is produced is exactly what i'm looking for.
The problem is when I assign the returned char* to the char** via arr[x]= i get the same char* in every element of arr[x]. I did try using the vector<char*> and it basically worked the same as the char** except without having to resize obviously.
on a few runs the char* were different in the arr[x] but did not match the char* produced by the someFunction, but did include pieces of the prior two char*s produced...
I realize i"m doing this in a more C way than C++ but am looking for the computational speed advantage this produces.
I realize i"m doing this in a more C way than C++ but am looking for the computational speed advantage this produces.
What makes you think there is a "computational advantage"?
Your structure (new[]'d array of pointers to first elements of different new[]'d arrays of char) is the same as vector<string> or vector<vector<char>> internally, but is a lot harder to use. It also cannot provide exception safety.
Start with vector<string>, then if accesses actually become a bottleneck, find out why (if you have a lot of column-wise traverses, e.g. the data is used as a matrix, then a matrix library could improve a few things). Don't use "new".