Hello;
I have 2 questions:
1- I know you can allocate memory to an array dinamically in C and C++. But, can this be done if the array is part of a structure?
2- Can the size of a dynamic array automatically grow up to a maximum or do you have to increase it when needed yourself?
This is my exact problem:
I want to have a table of a fixed number of rows like 30. These are for example nodes in a comupter network. Now, for each node, I want to keep track of the paths that it can be on. These would be in a column of the table named "paths". Each node may have hundreds of paths. So, I want to define the table as a struct and the "paths" as a big array. However, one node may end up with 300 paths and another with 2000 paths. I don't know this in advance.
Moreover, For each path, I need to keep track of the nodes that it passes through. So, each path is also defined as an array of a length let's say 10.
Below, I have specified how I am doing it now. But obviously, for large values I get an stack overflow error.
typedef struct //A row of the global routing table
{
int node;
int no_paths;
path_info paths[600]; //Plan for 600 paths per node.
}node_routing_info;
typedef struct
{
int path_id;
int length;
int prev_hops[10]; //maximum 10 hops per path
}path_info;
node_routing_info global_routing_info[30]; //no_elem= no_nodes.
P.S: If this cannot be done with structs, how can I do it with multi-dimentional arrays?
Your help is greatly appreciated.
Thanks
Ali