Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-Deque数组环形缓冲区_Python_Buffer_Ctypes_Deque - Fatal编程技术网

Python-Deque数组环形缓冲区

Python-Deque数组环形缓冲区,python,buffer,ctypes,deque,Python,Buffer,Ctypes,Deque,我的目标是: 使用capacity*ctypes.py_对象分配内存块, 使用系数为2的几何展开, 使用循环缓冲区方法来处理索引。 谁能给我指出正确的方向,我被卡住了。谢谢 class deque: capacity = 10 def __init__(self, size): self._data = (capacity * ctypes.py_object) self._size = 0 self._front = 0 def isEmpty(self):

我的目标是:

使用capacity*ctypes.py_对象分配内存块, 使用系数为2的几何展开, 使用循环缓冲区方法来处理索引。 谁能给我指出正确的方向,我被卡住了。谢谢

class deque:

capacity = 10

def __init__(self, size):
    self._data = (capacity * ctypes.py_object)
    self._size = 0
    self._front = 0

def isEmpty(self):
    return self._size == 0

def __len__(self):
    return self._size

def __getitem__(self, index):
    return self.list[index]

def addFront(self, item):
    self.items.append(item)

def addRear(self, item):
    self.items.insert(0, item)

def removeFront(self):
    return self.items.pop()

def removeRear(self):
    return self.items.pop(0)

听起来像是过早的优化。你试过collections.deque了吗?首先,对它进行分析,然后用它得出结论,你需要的ctypes通常很慢,除非你花很多时间在C上?@dstromberg是的,我是一个新手,我很难理解我是如何使用循环缓冲区和几何扩展来实现deque的