def test_realloc(self): #verify that TCMalloc accounts for resizing correctly measurements = [TCMallocNative.getBytesUsed()] for ix in range(10): addr = TCMallocNative.mallocAndReturnAddress(10 * 1024 * 1024) addr = TCMallocNative.reallocAtAddress(addr, 20 * 1024 * 1024) measurements.append(TCMallocNative.getBytesUsed()) addr = TCMallocNative.reallocAtAddress(addr, 10 * 1024 * 1024) addr = TCMallocNative.reallocAtAddress(addr, 5 * 1024 * 1024) TCMallocNative.freeAtAddress(addr) measurements.append(TCMallocNative.getBytesUsed()) self.assertTrue( measurements[-1] < measurements[0] + 10 * 1024 * 1024, "Expected %s to be less than 10 MB larger than %s" % (measurements[-1], measurements[0]))
def test_realloc(self): #verify that TCMalloc accounts for resizing correctly measurements = [TCMallocNative.getBytesUsed()] for ix in range(10): addr = TCMallocNative.mallocAndReturnAddress(10 * 1024 * 1024) addr = TCMallocNative.reallocAtAddress(addr, 20 * 1024 * 1024) measurements.append(TCMallocNative.getBytesUsed()) addr = TCMallocNative.reallocAtAddress(addr, 10 * 1024 * 1024) addr = TCMallocNative.reallocAtAddress(addr, 5 * 1024 * 1024) TCMallocNative.freeAtAddress(addr) measurements.append(TCMallocNative.getBytesUsed()) self.assertTrue( measurements[-1] < measurements[0] + 10 * 1024 * 1024, "Expected %s to be less than 10 MB larger than %s" % (measurements[-1], measurements[0]) )
def test_allocInOneThreadAndDeallocateInAnother(self): queue = Queue.Queue() thread = threading.Thread(target=memoryFreeingThreadLoop, args=(queue,)) thread.start() #allocate 100 GB and free in the other thread for ix in range(1000): event = threading.Event() address = TCMallocNative.mallocAndReturnAddress(100 * 1024 * 1024) queue.put((address, event)) event.wait() queue.put("exit") thread.join()
def test_allocInOneThreadAndDeallocateInAnother(self): queue = Queue.Queue() thread = threading.Thread(target=memoryFreeingThreadLoop, args=(queue, )) thread.start() #allocate 100 GB and free in the other thread for ix in range(1000): event = threading.Event() address = TCMallocNative.mallocAndReturnAddress(100 * 1024 * 1024) queue.put((address, event)) event.wait() queue.put("exit") thread.join()