[Pyrex] Efficient char* block to string conversion? (including embedded
nulls)
Michael Sparks
zathras at thwackety.com
Fri Jul 2 14:02:07 CEST 2004
Hi,
I've got some data referenced by a char* that I manage using a structure
like this:
ctypedef struct decode_buffer:
char * buffer
int len
int status
Into which a decode library gives me back some binary data. I've got a
method for copying this data out into a python string, which currently
looks like this:
if self.decodeBuffer.len >0:
r=['x']*self.decodeBuffer.len # I realise this is icky!
for i from 0 <= i < self.decodeBuffer.len:
j=self.decodeBuffer.buffer[i]
j= j & 255
r[i] = chr(j)
return ''.join(r)
else:
return ""
It's far from perfect I'm aware, but it does what I need it to - which is
nice. However it's not very efficient - is there any way of speeding this
up? (My only experience with python extensions is via Pyrex - so if it
involves delving inside python types, please assume I'm an idiot who knows
nothing!)
Many thanks in advance to any replies,
Michael.
More information about the Pyrex
mailing list