I am reading a book which is using ctypes
to create C Array in python.
import ctypes
class Array:
def __init__(self, size):
array_data_type = ctypes.py_object * size
self.size = size
self.memory = array_data_type()
for i in range(size):
self.memory[i] = None
I understand that self.memory = array_data_type()
is creating a memory chunk
which is basically a consecutive memory
having ctypes.py_object * size
as the total size.
How self.memory[i]
is related to self.memory
?
My understanding is that self.memory
has no indexing
and it is an object representing one single memory chunk.