GCC Middle and Back End API Reference
memory_block_pool Class Reference

#include <memory-block.h>

Collaboration diagram for memory_block_pool:

Data Structures

struct  block_list
 

Public Member Functions

 memory_block_pool ()
 
void reduce_free_list (int)
 

Static Public Member Functions

static voidallocate () ATTRIBUTE_MALLOC
 
static void release (void *)
 
static void trim (int nblocks=freelist_size)
 

Static Public Attributes

static const size_t block_size = 64 * 1024
 
static const size_t freelist_size = 1024 * 1024 / block_size
 

Private Attributes

block_listm_blocks
 

Static Private Attributes

static memory_block_pool instance
 

Detailed Description

Shared pool of memory blocks for pool allocators.
   Copyright (C) 2015-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Shared pool which allows other memory pools to reuse each others' allocated
memory blocks instead of calling free/malloc again.   

Constructor & Destructor Documentation

◆ memory_block_pool()

memory_block_pool::memory_block_pool ( )

Member Function Documentation

◆ allocate()

void * memory_block_pool::allocate ( )
inlinestatic
Allocate a single block.  Reuse a previously returned block, if possible.   

References block_size, ggc_alloc(), instance, m_blocks, memory_block_pool::block_list::m_next, NULL, and VALGRIND_DISCARD.

Referenced by mempool_obstack_chunk_alloc().

◆ reduce_free_list()

void memory_block_pool::reduce_free_list ( int num)
Reduce free list to NUM blocks and return remaining to malloc.   

References ggc_alloc(), m_blocks, memory_block_pool::block_list::m_next, and NULL.

Referenced by trim().

◆ release()

void memory_block_pool::release ( void * uncast_block)
inlinestatic

◆ trim()

void memory_block_pool::trim ( int num = freelist_size)
static
Return allocated memory back to malloc (and to system).   

References instance, and reduce_free_list().

Referenced by ggc_collect().

Field Documentation

◆ block_size

const size_t memory_block_pool::block_size = 64 * 1024
static

◆ freelist_size

const size_t memory_block_pool::freelist_size = 1024 * 1024 / block_size
static

◆ instance

memory_block_pool memory_block_pool::instance
staticprivate
Shared pool of memory blocks for pool allocators.
   Copyright (C) 2015-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Global singleton-like instance.   

Referenced by allocate(), release(), and trim().

◆ m_blocks

block_list* memory_block_pool::m_blocks
private

Referenced by allocate(), reduce_free_list(), and release().


The documentation for this class was generated from the following files: