I am trying to statically allocate memory to an array of pointers to a struct called "mini". The "mini" structs serve as a way to store an index and the data so I can do an indirect sort by sorting a pointer to the struct. When I declare the array, the array is allocated memory to store the pointers, but the pointers themselves are not allocated any memory for the "mini" structs. It is important that it is statically allocated because it is part of a sorting algorithm, so I am trying to avoid dynamic memory allocation.
This is the declaration of mini and an array of pointers to mini:
typedef struct {
long long index;
string data;
} mini;
static mini* ssn[1010000];
I can dynamically allocate as follows:
for (int j = 0; j < 1010000; j++){
ssn[j] = new mini();
}
The problem arises when I try to statically allocate memory to each of the pointers. Here are a few things I have tried:
static mini* ssn[1010000] = {{0,""}};
static mini* ssn[1010000] = {{new mini()}};
None of these compile successfully. Is there any way to statically allocate memory for each pointer in the array?