Fixed residual memory consumed by end cap stencils

An earlier change improved transient memory used during the construction
of end cap stencil tables but could leave unused capacity in the internal
containers of the resulting stencil tables. This change adds an additional
internal factory helper method which trims this storage.
This commit is contained in:
David G Yu 2016-03-15 11:36:34 -07:00 committed by David G Yu
parent a6fe9261ae
commit 841f573224
2 changed files with 21 additions and 2 deletions

View File

@ -1304,14 +1304,14 @@ PatchTableFactory::populateAdaptivePatches(
// finalize end patches // finalize end patches
if (localPointStencils and localPointStencils->GetNumStencils() > 0) { if (localPointStencils and localPointStencils->GetNumStencils() > 0) {
localPointStencils->generateOffsets(); localPointStencils->finalize();
} else { } else {
delete localPointStencils; delete localPointStencils;
localPointStencils = NULL; localPointStencils = NULL;
} }
if (localPointVaryingStencils and localPointVaryingStencils->GetNumStencils() > 0) { if (localPointVaryingStencils and localPointVaryingStencils->GetNumStencils() > 0) {
localPointVaryingStencils->generateOffsets(); localPointVaryingStencils->finalize();
} else { } else {
delete localPointVaryingStencils; delete localPointVaryingStencils;
localPointVaryingStencils = NULL; localPointVaryingStencils = NULL;

View File

@ -208,6 +208,12 @@ protected:
// Reserves the table arrays (factory helper) // Reserves the table arrays (factory helper)
void reserve(int nstencils, int nelems); void reserve(int nstencils, int nelems);
// Reallocates the table arrays to remove excess capacity (factory helper)
void shrinkToFit();
// Performs any final operations on internal tables (factory helper)
void finalize();
protected: protected:
StencilTable() : _numControlVertices(0) {} StencilTable() : _numControlVertices(0) {}
StencilTable(int numControlVerts) StencilTable(int numControlVerts)
@ -419,6 +425,19 @@ StencilTable::reserve(int nstencils, int nelems) {
_weights.reserve(nelems); _weights.reserve(nelems);
} }
inline void
StencilTable::shrinkToFit() {
std::vector<int>(_sizes).swap(_sizes);
std::vector<Index>(_indices).swap(_indices);
std::vector<float>(_weights).swap(_weights);
}
inline void
StencilTable::finalize() {
shrinkToFit();
generateOffsets();
}
// Returns a Stencil at index i in the table // Returns a Stencil at index i in the table
inline Stencil inline Stencil
StencilTable::GetStencil(Index i) const { StencilTable::GetStencil(Index i) const {