日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python申请内存函数_Python Ctypes c函数的内存分配

發布時間:2025/5/22 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python申请内存函数_Python Ctypes c函数的内存分配 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我現在有一個python回調函數,它使用ctypes庫調用c函數。c函數需要一個指向一個結構的指針,例如animal_info_s,我實例化了這個結構并將它作為指向c函數的指針傳遞,它就可以工作了。我遇到的問題是,當我有多個線程調用回調時,我發現傳遞回來的信息在線程之間混淆了。在class animal_info_s(ctypes.Structure):

_fields_ = [('dog_type', ctypes.c_uint16),

('cat_type', ctypes.c_uint16),

('bird_type', ctypes.c_uint16),

('epoch_time', ctypes.c_uint16),

('more_information', ctypes.c_uint16)]

_mod = ctypes.cdll.LoadLibrary('bbuintflib.dll')

animal_info_s = animal_info_s()

get_animal_data = _mod.get_animal_data

get_animal_data.argtypes = [ctypes.POINTER(animal_info_s)]

get_animal_data.restype = ctypes.c_int

# Python Callback

def GetAnimalData():

animal_info_p = animal_info_s

res = get_animal_data(animal_info_p)

if (res != 0):

print("Failed to get animal info")

return

print ("Receive Time - %d\nDog: %d\nCat: %d\nBird:%d" %(animal_info_p.epoch_time,

animal_info_p.dog_type,

animal_info_p.cat_type,

animal_info_p.bird_type))

我想當我實例化這個結構時,它每次都使用相同的內存位置。如何為每個調用回調的線程創建一個新的內存位置?在

總結

以上是生活随笔為你收集整理的python申请内存函数_Python Ctypes c函数的内存分配的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。