【问题标题】:posix_memalign within pythonpython中的posix_memalign
【发布时间】:2010-01-25 11:40:32
【问题描述】:

我似乎无法弄清楚为什么以下内容不起作用

import ctypes
from ctypes.util import find_library
libc = ctypes.CDLL(find_library('c'))

userpointer = ctypes.c_void_p
sizeimage = 320*240*2

if libc.posix_memalign(userpointer, libc.getpagesize(), sizeimage) != 0:
    raise Exception('ENOMEM')

我正在尝试使用 v4l2 进行捕获。我无法分配内存。 我尝试通过ctypes.addressof(userpointer) 我试图将用户指针转换为 c_void_p 但还是什么都没有。

【问题讨论】:

  • 您为什么不使用pygst之类的东西?
  • 很多。一 - 我不想在特定项目中依赖 gstreamer。

标签: python ctypes


【解决方案1】:

您的代码中有两个问题:您将用户指针设为 ctypes.c_void_p type 而不是它的实例,并且您将作为用户指针的 void* 直接传递给 posix_memalign,而不是posix_memalign 需要的 void**。以下将做你想做的事:

import ctypes
from ctypes.util import find_library
libc = ctypes.CDLL(find_library('c'))

userpointer = ctypes.c_void_p()
sizeimage = 320*240*2

if libc.posix_memalign(ctypes.byref(userpointer), libc.getpagesize(),
                       sizeimage) != 0:
    raise Exception('ENOMEM')

【讨论】:

    猜你喜欢
    • 2021-12-09
    • 2011-03-23
    • 2014-11-12
    • 2011-08-06
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多