summaryrefslogtreecommitdiff
path: root/gcc/memory-block.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/memory-block.cc')
-rw-r--r--gcc/memory-block.cc34
1 files changed, 28 insertions, 6 deletions
diff --git a/gcc/memory-block.cc b/gcc/memory-block.cc
index 507feaed157..ebf8cdd1e53 100644
--- a/gcc/memory-block.cc
+++ b/gcc/memory-block.cc
@@ -28,15 +28,30 @@ memory_block_pool memory_block_pool::instance;
memory_block_pool::memory_block_pool () : m_blocks (NULL) {}
-/* Return all blocks from free list to the OS. */
+/* Reduce free list to NUM blocks and return remaining to malloc. */
void
-memory_block_pool::clear_free_list ()
+memory_block_pool::reduce_free_list (int num)
{
- while (m_blocks)
+ block_list **blocks = &m_blocks;
+
+ /* First skip NUM blocks. */
+
+ for (;num > 0 && *blocks; num--)
+ blocks = &(*blocks)->m_next;
+
+ if (!*blocks)
+ return;
+
+ /* And free the remainder of them. */
+
+ block_list *to_free = *blocks;
+ *blocks = NULL;
+
+ while (to_free)
{
- block_list *next = m_blocks->m_next;
- XDELETEVEC (m_blocks);
- m_blocks = next;
+ block_list *next = to_free->m_next;
+ XDELETEVEC (to_free);
+ to_free = next;
}
}
@@ -62,3 +77,10 @@ mempool_obstack_chunk_free (void *chunk)
else
XDELETEVEC (chunk);
}
+
+/* Return allocated memory back to malloc (and to system). */
+void
+memory_block_pool::trim (int num)
+{
+ instance.reduce_free_list (num);
+}