ctypes.create_string_buffer
Prev: ctypes.cast | Up: ctypes | Next: ctypes.create_unicode_buffer
Rel: ctypes.addressof, ctypes.alignment, ctypes.ArgumentError, ctypes.Array
Ref: docs.python.org — ctypes.create_string_buffer
Tags: #public #python3 #stdlib #ctypes
Import
import ctypes
from ctypes import create_string_buffer
Signature & Overview
ctypes.create_string_buffer(init, size=None)
create_string_buffer(anInteger) -> character array create_string_buffer(aBytes, anInteger) -> character array
Usage
import ctypes
buf = ctypes.create_string_buffer(b"hello", 16)
assert len(buf) == 16 and buf.value == b"hello" and buf.raw.startswith(b"hello\x00")
Gotchas
- Mutable C char array (
c_char * N): Safe for C functions that write output strings;.valuestops at the first NUL byte,.rawreturns allNbytes.
REPL Inspect
from ctypes import create_string_buffer
help(create_string_buffer)
Linked from
Related notes
- tuts/python3/stdlib_module/ctypes/cast Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/create_unicode_buffer Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ctypes/addressof Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/alignment Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/ArgumentError Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/Array Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/BigEndianStructure shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/BigEndianUnion shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/byref shared tags: #ctypes, #stdlib