mariadb/storage/xtradb/include/mem0pool.h

122 lines
3.7 KiB
C
Raw Normal View History

2009-03-25 23:11:11 -07:00
/*****************************************************************************
2013-12-16 15:38:05 +01:00
Copyright (c) 1994, 2009, Oracle and/or its affiliates. All Rights Reserved.
2009-03-25 23:11:11 -07:00
This program 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; version 2 of the License.
This program 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
2013-12-16 15:38:05 +01:00
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
2009-03-25 23:11:11 -07:00
*****************************************************************************/
2009-09-07 10:22:53 +00:00
/**************************************************//**
@file include/mem0pool.h
The lowest-level memory management
Created 6/9/1994 Heikki Tuuri
*******************************************************/
#ifndef mem0pool_h
#define mem0pool_h
#include "univ.i"
#include "os0file.h"
#include "ut0lst.h"
2009-09-07 10:22:53 +00:00
/** Memory pool */
2013-12-16 15:38:05 +01:00
struct mem_pool_t;
2009-09-07 10:22:53 +00:00
/** The common memory pool */
extern mem_pool_t* mem_comm_pool;
2009-09-07 10:22:53 +00:00
/** Memory area header */
2013-12-16 15:38:05 +01:00
struct mem_area_t{
2009-09-07 10:22:53 +00:00
ulint size_and_free; /*!< memory area size is obtained by
anding with ~MEM_AREA_FREE; area in
a free list if ANDing with
MEM_AREA_FREE results in nonzero */
UT_LIST_NODE_T(mem_area_t)
2009-09-07 10:22:53 +00:00
free_list; /*!< free list node */
};
2009-09-07 10:22:53 +00:00
/** Each memory area takes this many extra bytes for control information */
2013-12-16 15:38:05 +01:00
#define MEM_AREA_EXTRA_SIZE (ut_calc_align(sizeof(struct mem_area_t),\
UNIV_MEM_ALIGNMENT))
2009-09-07 10:22:53 +00:00
/********************************************************************//**
Creates a memory pool.
@return memory pool */
UNIV_INTERN
mem_pool_t*
mem_pool_create(
/*============*/
2009-09-07 10:22:53 +00:00
ulint size); /*!< in: pool size in bytes */
/********************************************************************//**
2010-01-06 04:00:14 -08:00
Frees a memory pool. */
UNIV_INTERN
void
mem_pool_free(
/*==========*/
mem_pool_t* pool); /*!< in, own: memory pool */
/********************************************************************//**
Allocates memory from a pool. NOTE: This low-level function should only be
2009-09-07 10:22:53 +00:00
used in mem0mem.*!
@return own: allocated memory buffer */
UNIV_INTERN
void*
mem_area_alloc(
/*===========*/
2009-09-07 10:22:53 +00:00
ulint* psize, /*!< in: requested size in bytes; for optimum
space usage, the size should be a power of 2
minus MEM_AREA_EXTRA_SIZE;
out: allocated size in bytes (greater than
or equal to the requested size) */
2009-09-07 10:22:53 +00:00
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Frees memory to a pool. */
UNIV_INTERN
void
mem_area_free(
/*==========*/
2009-09-07 10:22:53 +00:00
void* ptr, /*!< in, own: pointer to allocated memory
buffer */
2009-09-07 10:22:53 +00:00
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Returns the amount of reserved memory.
@return reserved mmeory in bytes */
UNIV_INTERN
ulint
mem_pool_get_reserved(
/*==================*/
2009-09-07 10:22:53 +00:00
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Validates a memory pool.
@return TRUE if ok */
UNIV_INTERN
ibool
mem_pool_validate(
/*==============*/
2009-09-07 10:22:53 +00:00
mem_pool_t* pool); /*!< in: memory pool */
/********************************************************************//**
Prints info of a memory pool. */
UNIV_INTERN
void
mem_pool_print_info(
/*================*/
2009-09-07 10:22:53 +00:00
FILE* outfile,/*!< in: output file to write to */
mem_pool_t* pool); /*!< in: memory pool */
#ifndef UNIV_NONINL
#include "mem0pool.ic"
#endif
#endif