简体   繁体   中英

python ctypes arrays

I would like to have an array of variable length arrays in ctypes. I know the size of the outer array and all of the inner arrays, too.

I found an interesting thread here: How do I emulate a dynamically sized C structure in Python using ctypes

But the problem with this is how to create an array of Var classes (see the comment How do I emulate a dynamically sized C structure in Python using ctypes )

Maybe it's something that i cannot do with ctypes at all, i don't really know, i'm getting to know the module only for some hours, any pointers are appreciated.

Thank you!

Dynamically sized data structures are handled in ctypes the same way they are in C; you use pointers to dynamic data. Unfortunately, there's no shortcut on this one. The ctypes documentation includes fairly detailed descriptions on how to handle pointers to dynamic data (such as using a pointer as an arbitrarily sized array). It can be a little hard to grasp at first though. Personally, I've found that creating a few small test applications is helpful in verifing my use of ctypes and dynamic data. It may take some time and a little head-scratching but the interface is pretty flexible so I would expect that you'll be able to accomplish your goal using ctypes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM