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 void * allocate () 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-2025 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 ( )

References m_blocks, and NULL.

Member Function Documentation

◆ allocate()

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

References block_size, instance, 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 m_blocks, memory_block_pool::block_list::m_next, and NULL.

◆ release()

void memory_block_pool::release ( void * uncast_block)
inlinestatic
Return UNCAST_BLOCK to the pool.

References block_size, instance, memory_block_pool::block_list::m_next, and VALGRIND_DISCARD.

Referenced by mempool_obstack_chunk_free().

◆ trim()

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

References instance.

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-2025 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

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