Skip to content

Provide ctypes.memoryview_at() #112015

Closed
@rianhunter

Description

@rianhunter

Feature or enhancement

Proposal:

It should be possible to easily make memoryview objects from pointer-able ctypes objects with an arbitrary length. In the same way we can currently use ctypes.string_at() to create bytes objects. The advantage of using memoryview objects is that we can elide a buffer copy.

import ctypes
a = (ctypes.c_ubyte * 10)()
ctypes.buffer_at(a, 10, True)[0] = 1
assert a[0] == 1
a[0] = 2
assert ctypes.buffer_at(a, 10, True)[0] == 2

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-ctypestype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions