reduce size of blocks returned to pool

This commit is contained in:
Alexander 2017-09-19 00:14:44 +03:00
parent 44c2698f69
commit db08235c05
2 changed files with 6 additions and 1 deletions

View File

@ -3473,7 +3473,7 @@ _set_blocks_max(PyObject* self, PyObject* args)
static PyObject*
_clear_cache(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":_clear_cache"))
if (!PyArg_ParseTuple(args, ":clear_cache"))
return NULL;
ImagingMemoryClearCache(&ImagingDefaultArena, 0);

View File

@ -353,6 +353,11 @@ void
memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block)
{
if (arena->blocks_cached < arena->blocks_max) {
// Reduce block size
if (block.size > arena->block_size) {
block.size = arena->block_size;
block.ptr = realloc(block.ptr, arena->block_size);
}
arena->blocks[arena->blocks_cached] = block;
arena->blocks_cached += 1;
} else {