抱歉爬了google找不太到的样子,来这找高手大大
import ctypes 外部的dll
C code 类似:
static char gp_huge_buffer[1024][1024];
unsigned char *GetBufferAddress(void){
//change gp_huge_buffer contain
return (unsigned char *)gp_huge_buffer;
}
Python 类似去呼叫dll:
mydll = ctypes.cdll.LoadLibrary(path)
mydll.GetBufferAddress.argtypes = []
mydll.GetBufferAddress.restype = ctypes.POINTER(ctypes.c_ubyte)
# Google找到的,好像是在python中拷贝一份,而且好像不能用
p_ubyte = mydll.GetBufferAddress()
byte_array = c_ubyte * buffer_size
bytes = byte_array.from_address(hex(p_ubyte)) # error ! LP_c_ubyte cannot be
# interreted as integer
因为存资料的 buffer 是在 dll 中配置的,C 资料放进去想和 python 的 fd.read()比对
为了速度和内存考量下不想在python再重新从dll拷贝出来
请问有办法向C语言直接拿pointer存取GetBufferAddress回传位址中的任意byte吗?
ps 虽然不想用 bytes = byte_array.from_address(hex(p_ubyte))
但想请教一下这样是为什么报错呢?