Skip to Content.
Sympa Menu

charm - [charm] Pupping a vector of pointers

charm AT lists.siebelschool.illinois.edu

Subject: Charm++ parallel programming system

List archive

[charm] Pupping a vector of pointers


Chronological Thread 
  • From: Robert Steinke <rsteinke AT uwyo.edu>
  • To: Charm Mailing List <charm AT cs.illinois.edu>
  • Subject: [charm] Pupping a vector of pointers
  • Date: Thu, 5 Mar 2015 15:10:53 -0700
  • Authentication-results: cs.illinois.edu; dkim=none (message not signed) header.d=none;
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/charm/>
  • List-id: CHARM parallel programming system <charm.cs.uiuc.edu>

Something came up in my code that I think might be generally useful. I want to pup a std::vector of pointers. The objects that the pointers point to have pup routines. The code in pup_stl.h, in the process of pupping the vector, tries to pup each element in the vector. But the elements in the vector aren't the puppable objects. They are pointers to those objects. I came up with this solution:

// This is a general function to pup a puppable object via a pointer to it.
template <typename T> inline void operator|(PUP::er &p, T* &pointer)
{
bool notNull = (NULL != pointer);

p | notNull;

if (notNull)
{
if (p.isUnpacking())
{
pointer = new T;
}

p | *pointer;
}
else
{
pointer = NULL;
}
}

It seems like this could be generally useful for any situation where you want to pup a pointer to a puppable object. Would you consider this as an addition to the Charm++ codebase?



BTW, the reason my code has a std::vector of pointers is that I want a vector of objects of various subclasses of a single base class. To do this I have a vector of pointers to the base class pointing to dynamically allocated objects of the various subclasses.

Bob Steinke





Archive powered by MHonArc 2.6.16.

Top of Page