C type buffer copy
Hello, How does Python deal with C type memory buffers. Does Python return everything as an object irrespective of the data type? Here's what i am trying to achieve? testCode(unsigned char buf, unsigned long len) { unsigned long data=0x0; while (len--) { *buf++ = (unsigned char)data++ } } What's the best way to deal with this in python? -Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: C type buffer copy
Hi All-- def testCode(data): buf=data[:] # and I hope you're going to do something with buf, # because otherwise this function's a bit of a waste;-) [EMAIL PROTECTED] wrote: Hello, How does Python deal with C type memory buffers. Does Python return everything as an object irrespective of the data type? Here's what i am trying to achieve? testCode(unsigned char buf, unsigned long len) { unsigned long data=0x0; while (len--) { *buf++ = (unsigned char)data++ } } What's the best way to deal with this in python? Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: C type buffer copy
Joe: testCode(unsigned char buf, unsigned long len) { unsigned long data=0x0; while (len--) { *buf++ = (unsigned char)data++ This C code will crash since buf is declared as an unsigned char, not an unsigned char*. Stop thinking in terms of translating low level C because Python is a higher level language and does not have machine address pointers. You should be implementing the intent of your design which we can't determine from tiny incorrect snippets. For example, we can't determine if the intent is to create a new string, translation: ''.join([chr(x) for x in range(len)]), or if you are modifying an existing sequence or inserting into a sequence. It is also impossible to tell if you should be using a list, array or string for this job. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: C type buffer copy
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: What's the best way to deal with this in python? I can't tell what you're trying to do. If you want an array containing the numbers 0,1,...,n-1, just say buf = range(n) -- http://mail.python.org/mailman/listinfo/python-list