create_string_buffer()
来源:互联网 发布:淘宝售后客服工作总结 编辑:程序博客网 时间:2024/06/05 07:13
You should be careful, however, not to pass them to functions expecting pointers to mutable memory. If you need mutable memory blocks, ctypes has acreate_string_buffer()
function which creates these in various ways. The current memory block contents can be accessed (or changed) with the raw
property; if you want to access it as NUL terminated string, use the value
property:
The create_string_buffer()
function replaces the c_buffer()
function (which is still available as an alias), as well as the c_string()
function from earlier ctypes releases. To create a mutable memory block containing unicode characters of the C type wchar_t
use the create_unicode_buffer()
function.
Sometimes a C api function expects a pointer to a data type as parameter, probably to write into the corresponding location, or if the data is too large to be passed by value. This is also known as passing parameters by reference.
ctypes
exports the byref()
function which is used to pass parameters by reference. The same effect can be achieved with the pointer()
function, althoughpointer()
does a lot more work since it constructs a real pointer object, so it is faster to use byref()
if you don’t need the pointer object in Python itself:
ctypes.
create_string_buffer
(init_or_size[, size])This function creates a mutable character buffer. The returned object is a ctypes array of c_char
.
init_or_size must be an integer which specifies the size of the array, or a string which will be used to initialize the array items.
If a string is specified as first argument, the buffer is made one item larger than the length of the string so that the last element in the array is a NUL termination character. An integer can be passed as second argument which allows specifying the size of the array if the length of the string should not be used.
If the first parameter is a unicode string, it is converted into an 8-bit string according to ctypes conversion rules.
- create_string_buffer()
- Python ctypes 里使用 create_string_buffer, addressof, string_at
- JavaMail发送邮件
- linux-file_operations结构体分析记录
- Android应用从建项目开始
- 程序员常用网站
- OpenMP
- create_string_buffer()
- android设置全屏和横屏
- Maximum function nesting level of '100' reached, aborting!--漫谈递归:PHP里的尾递归及其优化
- S_ISREG S_ISDIR 等几个常见的宏
- 什么是代码缩进(code indent)
- BigDecimal的使用
- alembicTool_lsObject
- .NET 实验2-2
- 事件捕获和事件冒泡