* Remove own memory classes, which have now been broken out into their own package

This commit is contained in:
Matthew Honnibal 2014-09-17 23:10:07 +02:00
parent ac522e2553
commit 316a57c4be
2 changed files with 0 additions and 53 deletions

View File

@ -1,12 +0,0 @@
from libcpp.vector cimport vector
from cymem.cymem cimport Pool
cdef class _Pool:
cdef vector[void*] _addresses
cdef void* alloc(self, size_t number, size_t size) except NULL
cdef void* realloc(self, void* addr, size_t n) except NULL
cdef class Address:
cdef size_t addr

View File

@ -1,41 +0,0 @@
from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
from libc.string cimport memset
from libcpp.vector cimport vector
from cymem cimport Pool
cdef class Pool:
def __cinit__(self):
pass
def __dealloc__(self):
cdef void* addr
for addr in self._addresses:
PyMem_Free(<void*>addr)
cdef void* alloc(self, size_t number, size_t size) except NULL:
cdef void* addr = PyMem_Malloc(number * size)
memset(addr, 0, number * size)
self._addresses.push_back(addr)
return addr
cdef void* realloc(self, void* addr, size_t n) except NULL:
cdef size_t i
for i in range(self.size()):
if self._addresses[i] == addr:
self._addresses[i] = PyMem_Realloc(addr, n)
return self._addresses[i]
else:
raise MemoryError("Address to realloc not found in pool")
cdef class Address:
def __cinit__(self, size_t number, size_t size):
cdef void* addr = PyMem_Malloc(number * size)
memset(addr, 0, number * size)
self.addr = <size_t>addr
def __dealloc__(self):
PyMem_Free(<void*>self.addr)