One two-dimensional or two-dimensional array?

Hi Toaster!

There are three types of information (Name, Surname, Patronymic), I need them sorted for future use.
What to choose? Single multidimensional array or a plurality of one-dimensional?

// create one-dimensional arrays
string *name = new int [1000];
string *s_name = new int [1000];
string *m_name = new int [1000];

// OR

string **full_name = new string* [3]; 
for (int i = 0; i < 3; i++) { 
 full_name[W] = new string [1000]; // create a two-dimensional array
}


// ... operations on arrays (bonding of strings, substring search) ... 


// Clear memory
delete [] name; 
delete [] s_name; 
delete [] m_name; 

for (int i = 0; i < 3; i++) {
 delete [] full_name[i]; // delete two dimensional array
 }


Question: What is the better choice from the point of view of memory usage and performance?
After the operations the memory is released and fills the arrays with the new values. And so many times.

Thank you all in advance)
June 3rd 19 at 19:22
2 answers
June 3rd 19 at 19:24
Solution
What to choose?

Things don't get confused. Because the arrays you are already confused.
I would suggest a single array of structures with fields for name, surname and patronymic.

What is the better choice from the point of view of memory usage and performance?

It is better to choose something then don't get confused. If you will slow down -- run it through the Profiler and view the profiling results.
June 3rd 19 at 19:26
Solution
An array of structures, if not for learning, it is likely that the best choice would be std::vector, he will monitor the memory and expanding if necessary. The worst option is the second, where a pointer to a pointer, because the CPU cache will not be as effective

Find more questions by tags C++Arrays