itaps-parallel technical issues in iMeshP.h
Devine, Karen D
kddevin at sandia.gov
Mon Oct 6 14:21:12 CDT 2008
> On 10/3/08 12:20 PM, "Jason Kraftcheck" <kraftche at cae.wisc.edu> wrote:
>> Devine, Karen D wrote:
>>> On 10/2/08 3:46 PM, "Jason Kraftcheck" <kraftche at cae.wisc.edu> wrote:
>>> iMeshP_destroyPartitionAll
>>> - Why is 'partition_handle' inout? What is this function returning
>>> a handle to? Some other partition?
>>
>> The partition handle should be set to an invalid value when we destroy the
>> partition.
>>
>
> Why do we do this for partition handles, and not for any other type of
> handle? E.g.:
> iMesh_deleteEnt
> iMesh_deleteEntArr
> iMesh_destroyTag
> iMesh_destroyEntSet
> iMesh_endEntIter
> iMeshP_destroyPart
> and for that matter:
> free
> delete
> fclose
> etc.
Actually, I would ask why ITAPS doesn't invalidate handles for other types
of deletions (as in the list above). As a user, I'd like to have a handle
invalidated when it is no longer valid, so that I couldn't misuse it later.
And, yes, I wish "free" set its pointer argument to NULL after freeing
memory. So the true answer to your "why" question is that *I* wrote this
section of iMeshP instead of other ITAPS people. :)
Your example below is good, but in a C environment where users have to
destroyPartition themselves, I think invalidating the handle is a good idea.
In your example, you wouldn't have to send a temporary pointer to
destroyPartition; you would only have to remove the "const" definition. The
call to createPartition modifies the partition handle as well. Wouldn't
your class' constructor have to call createPartition? If not, from where
does the constructor get the partition handle?
Karen
>
> I think it is better not to do things that aren't necessary for the desired
> operation. Clearing the stale handle value for the caller unnecessarily
> restricts the caller. For example, assume I want to implement a C++ class
> in my application for which each instance manages a partition for me, taking
> care of releasing them, etc. Something like:
> class Partition {
> public:
> Partition( iMeshInstance instance, iMeshP_PartitionHandle handle )
> : myHandle(handle), myiMesh(instance) {}
>
> ~Partition() {
> int err;
> iMeshP_destroyPartitionAll(myiMesh, &myHandle, &err );
> }
>
> ...
>
> private:
> const iMeshP_PartitionHandle myHandle;
> const iMeshInstance myiMesh;
> };
>
> The above code will not compile as is. I want to declare the
> 'iMeshP_PartitionHandle myHandle' as const because I have no intention of
> changing it during the life of the object, but I cannot do so because
> iMeshP_destroyPartitionAll wants to clear the value when the object is
> destroyed. I could, of course, work around this by making a copy of
> myHandle to pass into iMeshP_destroyPartitionAll, but why force people to
> work around the API. Let the caller worry about clearing stale handle
> values if it wants to.
More information about the itaps-parallel
mailing list