I have a rather large, memory intensive program that I'm trying to slim down. Within this program are class instances parts of which have to persist to the end of the run and parts of which could be deleted earlier in order to slim things down. I know it may sound like a bad idea from a extensibility and reusability perspective, but I'd love to be able to destroy some STL vectors that become unnecessary to maintain. More specifically, I've got a "node" class with floats (x,y,z coords) and an stl vector that contains int indices of tetrahedra to which the nodes belong. STL works well here, because the number of tetrahedra varies from node to node.
Anyway, the code creates a vector of these nodes. After I do some things, I no longer need the vector of ints described above for each node. With millions of nodes, that space is precious to me.
So here's the question. Can I do something
inTetr = new vector<int>;
Is there a better way? And if I do it this way, how do I randomly access the entries? Thanks ahead of time for any help!
The functions are fairly singular in task. The problem is that logically, inTetr is part of the description of a node. It's a piece of information that's actually needed by a multitude of subroutines. However, the code rather dramatically "shifts gears". It's a finite element modeling code. inTetr is needed to create the mesh and populate the A and b of an Ax=b linear system. However, after that's done, I no longer need it. I do, however, need the x,y, and z coordinates of each node, so I cannot simply delete the nodes or allow them to go out of scope.
I could simply take inTetr out of the node class and eliminate the problem all together, but that sort of defeats the whole idea of objects and data encapsulation, which are perfect for a code like this.
Code proceeds as 1. Create model, which creates a mesh, which creates and connects together nodes and tetrahedra. 2. Populate A and b. 3. Solve Ax=b 4. do things that need mesh information, but not ALL mesh information. I could follow MrViggy's second suggestion by placing (1) in a scope, but the mesh and node objects cannot go out of scope. The logical choice seems to be to delete choice parts of node (and others, inTetr is just a single example). The solver for Ax=b is intensive, and could use the memory.
Incidentally, I originally wrote this code in F77, which I must admit made the math a lot more readable given the high level of F77. However, having a bunch of free floating vectors lying around like inTetr outside of node is exactly one of the things I'm trying to avoid using C++.