W
W
Waksim2018-07-21 06:59:16
C++ / C#
Waksim, 2018-07-21 06:59:16

One two-dimensional or two one-dimensional arrays?

Hi Toaster!
There are three types of information (First Name, Last Name, Patronymic), they need to be sorted for further use.
What to choose? One multi-dimensional array or many one-dimensional ones?

// создаем одномерные массивы
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[ш] = new string [1000];    // создаем двумерный массив
  }
    
    
// ... операции над массивами (склеивание строк, поиск подстроки) ... 
 

// Очистка памяти
delete [] name; 
delete [] s_name; 
delete [] m_name; 

for (int i = 0; i < 3; i++) {
    delete [] full_name[i];  // удаляем двумерный массив
  }

Question: What is the best choice in terms of memory usage and performance?
After the operations, the memory is freed and the arrays are stuffed with new values. And so many times.
Thank you all in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-07-21
@Waksim

What to choose?

Something that you won't get confused about later. Because in arrays you are already confused.
I would suggest one array of structures with fields for the first name, last name, and patronymic.
It is better to choose something in which you will not get confused later. If it slows down, run it through the profiler and look at the profiling results.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question