1

Topic: How it is correct storage?

I implement two-dimensional dynamic array. At its creation the amount of elements on both measurements precisely is not known.
Therefore it would be desirable somehow optimally  storage:
1. delete and new kill all piece of storage and create it on the new.
2. realloc does not transfer the old data to new storage,  it in parameters does not have size of old memory size.
How the similar task is better to solve?
p.s. The second measurement of arrays accepts great values (the one million order), the construction "an array of arrays" (instead of one piece in which by means of the sizes of an array and two indexes the current uniform index is defined) therefore is desirable.

2

Re: How it is correct storage?

I correctly understand, what function realloc receives the pointer on an old piece to try in the same place and to select storage?

3

Re: How it is correct storage?

AlekseySQL;
std::map<std::pair<size_t,size_t>,type_to_store>
It is possible to address to any pair (x / y), it is possible to check up element existence, it is possible not to store the missing.

4

Re: How it is correct storage?

AlekseySQL wrote:

2. realloc does not transfer the old data to new storage,  it in parameters does not have size of old memory size.

You are mistaken, realloc transfers http://www.cplusplus.com/reference/cstd … kw=realloc

AlekseySQL wrote:

p.s. The second measurement of arrays accepts great values (the one million order), the construction "an array of arrays" (instead of one piece in which by means of the sizes of an array and two indexes the current uniform index is defined) therefore is desirable.

You can make a vector

std:: vector <std:: vector <my_type_t>> arr;

5

Re: How it is correct storage?

Dima T;
Thanks for the help on realloc - did not think that it such clever!