[Matrix-SIG] Implementing a Record type.

Paul Barrett barrett@compass.gsfc.nasa.gov
Mon, 23 Nov 1998 17:27:16 -0500 (EST)


I have been working on implementing a 'record' object for Python for
the past few weeks and have run into an implementation problem.  I'm
hoping someone might lead me in the right direction.

This 'record' object that I'm trying to implement is basically a
generalization of the 'struct' module which enables packing and
unpacking of data in strings.  The difference is that a 'record' is an
object with array behaviour (as well as a few other features like
being able name an item of the record).  I also plan to provide a C
API for this object, so that I can embed it in another object which is
an array of records, like the array object in the numeric module.

The problem that I am having is how to deal with the data string.  For
a single record, this is not much of an issue, but for arrays of
records where the data is contiguous, this becomes more difficult, at
least from my perspective.  For example, suppose we have a 1-D array
of records and that we want to manipulate one record (i.e. 'rec' =
array_record[n]).  When I access this record, should I be accessing a
copy of this record or a pointer into the string buffer?  The problem
that I see is that changing the copy does not change the original
which is what I would expect it to do.  In addition, the latter
implementation appears to be more complicated, since your required to
keep track of the entire string buffer in case it disappears at some
stage. 

Any suggestions or thoughts on how best to implement this object type
will be most appreciated.

Cheers,
Paul