mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
clear_cache: number or blocks to keep
This commit is contained in:
parent
6a435793d8
commit
4b85230726
|
@ -129,14 +129,15 @@ class TestCoreMemory(PillowTestCase):
|
|||
Image.core.set_block_size(4096)
|
||||
Image.new('RGB', (256, 256))
|
||||
Image.new('RGB', (256, 256))
|
||||
Image.core.clear_cache()
|
||||
# Keep 16 blocks in cache
|
||||
Image.core.clear_cache(16)
|
||||
|
||||
stats = Image.core.get_stats()
|
||||
self.assertGreaterEqual(stats['new_count'], 2)
|
||||
self.assertGreaterEqual(stats['allocated_blocks'], 64)
|
||||
self.assertGreaterEqual(stats['reused_blocks'], 64)
|
||||
self.assertGreaterEqual(stats['freed_blocks'], 64)
|
||||
self.assertEqual(stats['blocks_cached'], 0)
|
||||
self.assertGreaterEqual(stats['freed_blocks'], 48)
|
||||
self.assertEqual(stats['blocks_cached'], 16)
|
||||
|
||||
def test_large_images(self):
|
||||
Image.core.reset_stats()
|
||||
|
|
|
@ -3466,10 +3466,12 @@ _set_blocks_max(PyObject* self, PyObject* args)
|
|||
static PyObject*
|
||||
_clear_cache(PyObject* self, PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":clear_cache"))
|
||||
int i = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i:clear_cache", &i))
|
||||
return NULL;
|
||||
|
||||
ImagingMemoryClearCache(&ImagingDefaultArena, 0);
|
||||
ImagingMemoryClearCache(&ImagingDefaultArena, i);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
|
Loading…
Reference in New Issue
Block a user