Design question

I have a program like this: from the main function I create an instance from a certain kind, called TextManager. It calls a method, this one calls another one that calls a third method that doesn't call anything. A hierarchy like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 main () {
..........
TextManager textManager.a();

  TextManager::a () {
      ................
      b();
}
  TextManager::b () {
      .....
     c();
}
  TextManager::c () {
      .....
     ......
}


C gets numeric values that are sent to b through reference parameters. In B these numeric values are attributed to an structure created right there, in B.
Them I send a reference to this structure to a vector belonging to a second class. A hierarchy like this:
1
2
3
4
5
6
7
 TextManager::b (Scene &scene) {
      .....
     c();
     Material material;
     scene.addMaterial (const Material &material); 
}
     inline void addMaterial (const Material &material) { materialContainer.push_back (material); } 


Them, as can be seem from above, in "addMaterial" the structure is added to a vector.
The problem it is that I will need the data stored in the structures from the kind "Material" (there are many, because I am creating the structures inside a loop) well after method b ends, which means I end with a lot of trash stored in "materialContainer".
The first solution I thought was to allocate memory dynamically in the heap with pointers, but vectors only accept const references.

So which are good design solutions to my dilemma?

Return the data to the main function and add the structures from there to the vector belonging to scene? If that is a good choice, it would be better to retrieve the data through return statements or through reference parameters?

Or there are better ways?

Thanks for the help.



Last edited on
Topic archived. No new replies allowed.