抱歉爬了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))
但想請教一下這樣是為甚麼報錯呢?