Introducing Pointers in Python using the Ctypes Library

  Рет қаралды 6,009

CodersLegacy

CodersLegacy

Күн бұрын

In this tutorial we will explore how we can introduce Pointers into Python using the ctypes library, as well as how to allocate and deallocate dynamic memory.
Website Link: coderslegacy.com/python/ctype...
Related Links:
Ctypes Basics: • Python ctypes Tutorial...
Ctypes Datatypes and Strings: • Python ctypes Library ...
Ctypes with C++: • Ctypes Library - How t...

Пікірлер: 17
@chaxiraxi_ytb
@chaxiraxi_ytb 4 ай бұрын
This video series is so underrated thank you so much
@russianvodka666
@russianvodka666 Жыл бұрын
The feeling when it is not clear in the documentation, but the KZbin person explained everything. You're beautiful! Like!
@seamusrohe9226
@seamusrohe9226 Жыл бұрын
Subbed. @CodersLegacy your videos are amazing! The concise and steady pace that you present these concepts is so easy to follow along with, you really have a knack for making these videos. Keep up the good work! I've been really struggling with ctypes (using C++) and even your videos on ctypes with C are so helpful. I can't wait for more content about C++. Do you have a discord I'd love to be able to ask you a few questions if you have t he time? There are VERY few good videos or any form of toutorials on this subject I was so happy when i found your channel.
@MARIO-tb3tr
@MARIO-tb3tr Жыл бұрын
Very very helpful
@JohnWolf-ir7qg
@JohnWolf-ir7qg Жыл бұрын
LP in the returned contents of the ctype C string stands for Long Pointer.
@coderslegacy5661
@coderslegacy5661 Жыл бұрын
Thanks for sharing!
@undeadpresident
@undeadpresident Жыл бұрын
I have been using ctypes to speed up my python code. I don't see why you would think this is a bad idea. I can't run cython or numba on my machine. Right now trying to figure out how to send a pointer of a pygame surface to ctypes so I can manually alter the data in C because python is slow af. I appreciate the vids though, saves me time trying to figure out what the documentation is saying when I can see it in action.
@coderslegacy5661
@coderslegacy5661 Жыл бұрын
It's certainly not a bad idea. It's an obvious performance benefit, which I even made a video on recently. But if it comes down to a situation between Cython and Ctypes where both can be used, and your only concern is speed, then Cython would be a better choice. There are so many other factors too. Depends on the situation at hand and what you feel comfortable doing. Glad to see that my videos have been helping you by the way. Thanks for the feedback.
@undeadpresident
@undeadpresident Жыл бұрын
@@coderslegacy5661 Yeah I wanted to use cython but I have an older machine and was having compatibility issues with it (and numba) and wanted to learn C better anyway so I went with ctypes. I figured out how to get the surface data from pygame into C now. :) I used the pygame surfarray.pixels3d() function to get an array then passed it as a pointer to ctypes. The pointer created in python was 2 elements in from the actual start of the data so a negative index had to be used, and the real data was organized in Y,X instead of X,Y, and with the format RABG rather than RGB. ;)
@thetimeee1312
@thetimeee1312 Жыл бұрын
Straight forward tutorial but you should've explained in more detail why one wants to use pointers in the first place. We don't need to use neither pointers nor the heap to achieve whatever we want. We need to use pointers to achieve it as performant as possible by passing references instead of copying the whole memory of whatever we are trying to pass to methods etc.
@kcvinu
@kcvinu Жыл бұрын
Hi thanks for this video. I have a question. How do we pass a python class instance to a C function and get it back from another C function ? For example, Let's say I have a Window class in python. After creating the window, I just need to pass the self pointer to "SetWindowLongPtr" function. Then I can get my Window object inside the WndProc function, with the help of GetWindowLongPtr function. How to do this ?
@undeadpresident
@undeadpresident Жыл бұрын
the next video in his series covers passing classes to C code as structs
@kcvinu
@kcvinu Жыл бұрын
@@undeadpresident Great, thank you:)
@undeadpresident
@undeadpresident Жыл бұрын
@@kcvinu np
@ravigandhi1698
@ravigandhi1698 Жыл бұрын
How do we use enum in ctypes
@ReinventedWeb
@ReinventedWeb 2 жыл бұрын
What sorcery is this? Pointers in python?? Witch.
@coderslegacy5661
@coderslegacy5661 2 жыл бұрын
It's Dark Magic.
Using Arrays with Python Ctypes
16:19
CodersLegacy
Рет қаралды 4,2 М.
Python ctypes Library - Memory, Strings, Datatypes
16:47
CodersLegacy
Рет қаралды 8 М.
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 113 МЛН
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 25 МЛН
OMG😳 #tiktok #shorts #potapova_blog
00:58
Potapova_blog
Рет қаралды 2,9 МЛН
Using Structs and Classes with Python Ctypes
25:37
CodersLegacy
Рет қаралды 4,8 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 792 М.
Cython makes Python INSANELY FAST
19:08
Carberra
Рет қаралды 32 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
Python Asynchronous Programming - AsyncIO & Async/Await
25:57
Tech With Tim
Рет қаралды 415 М.
super/MRO, Python's most misunderstood feature.
21:07
mCoding
Рет қаралды 212 М.
Ctypes Library - How to use C++ Functions in Python Code
15:41
CodersLegacy
Рет қаралды 6 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,1 МЛН
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 294 М.
THIS is Why List Comprehension is SO Efficient!
5:25
b001
Рет қаралды 169 М.
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 113 МЛН