summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRian Hunter <rianhunter@users.noreply.github.com>2025-01-03 13:07:07 (GMT)
committerGitHub <noreply@github.com>2025-01-03 13:07:07 (GMT)
commitb4f799b1e78ede17b41de9a2bc51b437a7e6dd74 (patch)
tree6b9c169612eefd8ee78b113bb39f2cb9c3aa24b0 /Doc/library
parentf21af186bf21c1c554209ac67d78d3cf99f7d7c0 (diff)
downloadcpython-b4f799b1e78ede17b41de9a2bc51b437a7e6dd74.zip
cpython-b4f799b1e78ede17b41de9a2bc51b437a7e6dd74.tar.gz
cpython-b4f799b1e78ede17b41de9a2bc51b437a7e6dd74.tar.bz2
gh-112015: Implement `ctypes.memoryview_at()` (GH-112018)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/ctypes.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index 09692e5..398cb92 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -2182,6 +2182,28 @@ Utility functions
.. audit-event:: ctypes.wstring_at ptr,size ctypes.wstring_at
+.. function:: memoryview_at(ptr, size, readonly=False)
+
+ Return a :class:`memoryview` object of length *size* that references memory
+ starting at *void \*ptr*.
+
+ If *readonly* is true, the returned :class:`!memoryview` object can
+ not be used to modify the underlying memory.
+ (Changes made by other means will still be reflected in the returned
+ object.)
+
+ This function is similar to :func:`string_at` with the key
+ difference of not making a copy of the specified memory.
+ It is a semantically equivalent (but more efficient) alternative to
+ ``memoryview((c_byte * size).from_address(ptr))``.
+ (While :meth:`~_CData.from_address` only takes integers, *ptr* can also
+ be given as a :class:`ctypes.POINTER` or a :func:`~ctypes.byref` object.)
+
+ .. audit-event:: ctypes.memoryview_at address,size,readonly
+
+ .. versionadded:: next
+
+
.. _ctypes-data-types:
Data types