일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- Decorator
- 43. Multiply Strings
- 시바견
- 파이썬
- Python Implementation
- 운영체제
- 30. Substring with Concatenation of All Words
- kaggle
- Python Code
- Generator
- attribute
- Regular Expression
- 315. Count of Smaller Numbers After Self
- Python
- iterator
- data science
- 715. Range Module
- 밴픽
- 109. Convert Sorted List to Binary Search Tree
- Class
- 프로그래머스
- LeetCode
- DWG
- t1
- Protocol
- shiba
- concurrency
- Substring with Concatenation of All Words
Archives
- Today
- Total
Scribbling
Python: Memoryview function 본문
Python memoryview function returns memory view objects.
So why use it? Memory view is a safe way to expose 'buffer protocol' in python. Buffer protocol allows an object to expose its inner data without copying. As buffer protocol is only available at the C-API level, memoryview is present to expose the same protocol at Python level.
Example1: how memoryview works
arr = bytearray('XYZ', 'utf-8')
mv = memoryview(arr)
print(mv[0])
print(bytes(mv[0:1]))
Example2: how to modify internal data using memoryview
arr = bytearray('XYZ', 'utf-8')
mv = memoryview(arr)
print(arr)
mv[0] = 68
print(arr)
str = str(mv)
bt = bytes(mv)
print(str)
print(bt)
https://www.geeksforgeeks.org/memoryview-in-python/
'Computer Science > Python' 카테고리의 다른 글
Python: Decorator & Closure (0) | 2022.03.29 |
---|---|
Python: Design Patterns (0) | 2022.03.25 |
Python Immutable Dictionary, Set (0) | 2022.03.22 |
Python Data Structures: Sequences (0) | 2022.03.21 |
Python Magic Methods: Pythonic Data Model (0) | 2022.03.16 |