zero-copy array slicing

Trevor trevorperrin at hotmail.com
Tue Nov 19 15:38:49 EST 2002


Alex Martelli <aleax at aleax.it> wrote in message news:<JLqC9.37182
> > Is a zero-copy array slicing operation possible? [..]
>
> [..] if this the behavior you need, the simplest way to get it is exactly 
> with the Numeric extensions

Interesting, thanks!  However I don't think Numeric or Numarray
support the buffer interface (or come standard with python), which was
my reason for trying to use the array module.

What I'm trying to do is interface a C cryptography library to python,
so I can encrypt/hash data in as convenient and efficient a way as
possible.  I was thinking the buffer interface would be the best way
to get a grip on the contents of strings (for read-only operations
like hashing) and arrays.  If arrays had a subsequence() function then
I could efficiently hash or encrypt-in-place parts of arrays:

bytes = readArrayFromBigFile()
hash(bytes.subsequence(128))              #hash all but some header
encrypt(bytes)                            #encrypt whole array
encrypt(bytes.subsequence(start, finish)) #encrypt some section

I'd be willing to try to add this.  But maybe I should explore the
solution space more.  What would you recommend as the most Pythonic
approach, given these constraints?
 - in-place operation on subsequences of bytes, from the C api
 - convenient application to different types (e.g. strings, arrays)
 - ideally, no dependency on nonstandard libraries (like Numeric)

 
Trevor



More information about the Python-list mailing list