python 中指针_如何读取Python中的指针地址?

我碰巧也在研究类似的问题。我的python脚本load.so库从c++.so获取图像缓冲区地址。在我得到缓冲区地址之后,我需要能够读取缓冲区中的每个字节。我用“from_address”创建了一个列表对象:imageBytes = list(c_ubyte * dataSize).from_address(pointer)

下面详细介绍了如何获取从c++到pyth的内存地址,以及如何在python端访问内存数据。在c++代码中框架提供者.cpp公司名称:

^{pr2}$

我的Python:import ctypes

import binascii

lib = ctypes.cdll.LoadLibrary('/libpath/frameprovider.so')

print vars(lib)

class dataPack(ctypes.Structure):

_fields_ = [("width",ctypes.c_int),

("height",ctypes.c_int),

("buffersize",ctypes.c_int),

("bufferAddress", ctypes.c_void_p)]

lib.getFrame_wrapper.restype = ctypes.POINTER(dataPack)

data = lib.getFrame_wrapper()

print "in python the w= ", data.contents.width, "h=",data.contents.height

print "the buffersize=",data.contents.height

imageBytes = list(

(data.contents.buffersize * ctypes.c_ubyte).

from_address(data.contents.bufferAddress))

print "the len of imageBytes are ", len(imageBytes)

print imageBytes[data.contents.buffersize -1] #print the last byte in the buffer

print "in python, the hex value of element 12 is ", hex(imageBytes[12])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值