pointers

Does a pointer get freed when called indirectly in a function from a struct?

Does a pointer get freed when called indirectly in a function from a struct? Question: Say we have the following in Cython: ctypedef struct Structure: int* array int size cdef print_fx(Structure obj): print(obj.array[0]) cdef create_object(int size): cdef Structure result result.size = size result.array = <int*>malloc(size*sizeof(int)) for i in range(size): result.array[i] = 1 return result And …

Total answers: 1

ctypes character pointers with same byte string points same location

ctypes character pointers with same byte string points same location Question: I am creating two ctypes character pointers with same byte string via: import ctypes as ct var1 = ct.c_char_p(b’.’*80) var2 = ct.c_char_p(b’.’*80) # how I check the values: api = ct.CDLL(‘api.dll’) api.function1(var1, var2) # values of the vars are changed after running the above …

Total answers: 2

C++ vs Python | Read Memory

C++ vs Python | Read Memory Question: Have working code in C++ and would like to get equivalent results with Python. The idea is to retrieve data from memory using a specific process and a pointer. The result should look like this as it works in C++: Here is the C++ code: hProcess = SOME_HANDLER …

Total answers: 1

why the pointer is not incrementing at line 27

why the pointer is not incrementing at line 27 Question: i am implementing the trie data structure, why my pointer is not incrementing at line# 27. all the characters are getting into forst node only. this is my code class Trienode: data:str next:list = [None]*26 isTerminal:bool = False def __init__(self,data): self.data = data class Trie: …

Total answers: 1

How to pass a string pointer-to-pointer from C to Python?

How to pass a string pointer-to-pointer from C to Python? Question: I need to pass a string pointer-to-pointer from C to Python, so Python can update the pointer and C can read it later. Steps C set a char** C call Python Python allocate memory Python update the char** C read the string C Code: …

Total answers: 1

How do you check if a variable references another declared object in Python?

How do you check if a variable references another declared object in Python? Question: Printing type of one variable just returns the pointed data’s type i = [5,6,7,8] j = i print(type(j)) <class ‘list’> and j references a mutable type. So j[0] = 3 print(i) print(j) [3, 6, 7, 8] [3, 6, 7, 8] I …

Total answers: 2

Mallocing and Freeing in C, but passing the pointer through Python via ctypes

Mallocing and Freeing in C, but passing the pointer through Python via ctypes Question: I would like to put a malloc a function in C. I would then like to call this function from Python 3.10 via ctypes.DLL. I then would like to free it. However, I get a segmentation fault. Here’s my very simple …

Total answers: 1