Beispiel #1
0
class simple_allocator(object):
    def __init__(self):
        self.lock = threading.Lock()
        self.size = mmap.PAGESIZE
        self.offset = 0
        self.buf = SharedMemoryBuffer(self.size)

    def _allocate_tiny(self, size):
        free = self.size - self.offset
        if (size > free):
            self.size += mmap.PAGESIZE
            if (self.size > 1024**2): self.size = 1024**2
            self.buf = SharedMemoryBuffer(self.size)
            self.offset = size
            addr, _ = self.buf.getbuffer()
            return 0, self.buf
        else:
            offset = self.offset
            self.offset += size
            addr, _ = self.buf.getbuffer()
            return offset, self.buf

    def _allocate_big(self, size):
        buf = SharedMemoryBuffer(size)
        addr, _ = buf.getbuffer()
        return 0, buf

    def allocate(self, size):
        with self.lock:
            if size > mmap.PAGESIZE:
                offset, buf = self._allocate_big(size)
            else:
                offset, buf = self._allocate_tiny(size)
        return offset, buf
Beispiel #2
0
 def _allocate_tiny(self, size):
     free = self.size - self.offset
     if (size > free):
         self.size += mmap.PAGESIZE
         if (self.size > 1024**2): self.size = 1024**2
         self.buf = SharedMemoryBuffer(self.size)
         self.offset = size
         addr, _ = self.buf.getbuffer()
         return 0, self.buf
     else:
         offset = self.offset
         self.offset += size
         addr, _ = self.buf.getbuffer()
         return offset, self.buf
Beispiel #3
0
 def _allocate_tiny(self, size):
     free = self.size - self.offset
     if (size > free):
         self.size += mmap.PAGESIZE
         if (self.size > 1024**2): self.size = 1024**2
         self.buf = SharedMemoryBuffer(self.size)
         self.offset = size
         addr, _= self.buf.getbuffer()
         return 0, self.buf
     else:
         offset = self.offset
         self.offset += size
         addr, _= self.buf.getbuffer()
         return offset, self.buf
Beispiel #4
0
class simple_allocator(object):

    def __init__(self):
        self.lock = threading.Lock()
        self.size = mmap.PAGESIZE
        self.offset = 0
        self.buf = SharedMemoryBuffer(self.size)

    def _allocate_tiny(self, size):
        free = self.size - self.offset
        if (size > free):
            self.size += mmap.PAGESIZE
            if (self.size > 1024**2): self.size = 1024**2
            self.buf = SharedMemoryBuffer(self.size)
            self.offset = size
            addr, _= self.buf.getbuffer()
            return 0, self.buf
        else:
            offset = self.offset
            self.offset += size
            addr, _= self.buf.getbuffer()
            return offset, self.buf
            
    def _allocate_big(self, size):
        buf = SharedMemoryBuffer(size)
        addr, _ = buf.getbuffer()
        return 0, buf

        
    def allocate(self, size):
        with self.lock:
            if size > mmap.PAGESIZE:
                offset, buf = self._allocate_big(size)
            else:
                offset, buf = self._allocate_tiny(size)
        return offset, buf
Beispiel #5
0
 def _allocate_big(self, size):
     buf = SharedMemoryBuffer(size)
     addr, _ = buf.getbuffer()
     return 0, buf
Beispiel #6
0
 def __init__(self):
     self.lock = threading.Lock()
     self.size = mmap.PAGESIZE
     self.offset = 0
     self.buf = SharedMemoryBuffer(self.size)
Beispiel #7
0
 def _allocate_big(self, size):
     buf = SharedMemoryBuffer(size)
     addr, _ = buf.getbuffer()
     return 0, buf
Beispiel #8
0
 def __init__(self):
     self.lock = threading.Lock()
     self.size = mmap.PAGESIZE
     self.offset = 0
     self.buf = SharedMemoryBuffer(self.size)