일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Regular Expression
- DWG
- 운영체제
- 43. Multiply Strings
- Substring with Concatenation of All Words
- 파이썬
- Generator
- Python Code
- 315. Count of Smaller Numbers After Self
- LeetCode
- 프로그래머스
- Protocol
- iterator
- Python Implementation
- 30. Substring with Concatenation of All Words
- 컴퓨터의 구조
- shiba
- Decorator
- 시바견
- 109. Convert Sorted List to Binary Search Tree
- 715. Range Module
- concurrency
- 밴픽
- t1
- Convert Sorted List to Binary Search Tree
- attribute
- kaggle
- Class
- data science
- Python
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 |