Introducing Pointers in Python using the Ctypes Library

preview_player
Показать описание
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.

Related Links:
Рекомендации по теме
Комментарии
Автор

This video series is so underrated thank you so much

chaxiraxi_ytb
Автор

Excellent series. Really enjoying it and learning heaps. Thank you! .... Note: The use of ctypes.contents in the line ptr2.contents = num is incorrect because it causes erratic memory allocation and unpredictable behavior downstream. The correct approach is to use ptr2 = ctypes.pointer(num), which ensures that the pointer references the correct memory location without causing side effects. Noticed side-effects when defining further ptr3 with new values after the code you wrote. The values and pointers did not behave correctly. fixing ptr2 fixed the problem. ... anyway, thanks again. awesome vids.

ygvvzpl
Автор

The feeling when it is not clear in the documentation, but the YouTube person explained everything. You're beautiful! Like!

russianvodka
Автор

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.

seamusrohe
Автор

LP in the returned contents of the ctype C string stands for Long Pointer.

JohnWolf-irqg
Автор

Hi There, I faced a problem that the terminal will always print all Python Print then releases printf in C code. I searched plenty but failed to find a valid solution. Can you please give me a hand on it?

arjunfan
Автор

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.

thetimeee
Автор

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.

undeadpresident
Автор

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 ?

kcvinu
Автор

What sorcery is this? Pointers in python?? Witch.

ReinventedWeb