| 1 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
// vi: set et ts=4 sw=2 sts=2: |
| 3 |
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 4 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
/*! \file heaps.h |
| 6 |
* \ingroup low |
| 7 |
*/ |
| 8 |
|
| 9 |
/** \addtogroup low |
| 10 |
* |
| 11 |
* @{ |
| 12 |
*/ |
| 13 |
|
| 14 |
/****************************************************************************/ |
| 15 |
/* */ |
| 16 |
/* File: heaps.h */ |
| 17 |
/* */ |
| 18 |
/* Purpose: low-level memory management for ug */ |
| 19 |
/* */ |
| 20 |
/* Author: Peter Bastian */ |
| 21 |
/* Interdisziplinaeres Zentrum fuer Wissenschaftliches Rechnen */ |
| 22 |
/* Universitaet Heidelberg */ |
| 23 |
/* Im Neuenheimer Feld 368 */ |
| 24 |
/* 6900 Heidelberg */ |
| 25 |
/* */ |
| 26 |
/* History: 29.01.92 begin, ug version 2.0 */ |
| 27 |
/* */ |
| 28 |
/* Revision: 04.09.95 */ |
| 29 |
/* */ |
| 30 |
/****************************************************************************/ |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
/****************************************************************************/ |
| 35 |
/* */ |
| 36 |
/* auto include mechanism and other include files */ |
| 37 |
/* */ |
| 38 |
/****************************************************************************/ |
| 39 |
|
| 40 |
#ifndef __HEAPS__ |
| 41 |
#define __HEAPS__ |
| 42 |
|
| 43 |
#include <vector> |
| 44 |
|
| 45 |
#include "ugtypes.h" |
| 46 |
#include "namespace.h" |
| 47 |
|
| 48 |
START_UG_NAMESPACE |
| 49 |
|
| 50 |
/****************************************************************************/ |
| 51 |
/* */ |
| 52 |
/* defines in the following order */ |
| 53 |
/* */ |
| 54 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 55 |
/* other constants */ |
| 56 |
/* macros */ |
| 57 |
/* */ |
| 58 |
/****************************************************************************/ |
| 59 |
|
| 60 |
/****************************************************************************/ |
| 61 |
/* defines for the simple and general heap management */ |
| 62 |
/****************************************************************************/ |
| 63 |
|
| 64 |
/** \brief Smallest heap to allocate */ |
| 65 |
#define MIN_HEAP_SIZE 256 |
| 66 |
/** \brief Max depth of mark/release calls */ |
| 67 |
#define MARK_STACK_SIZE 128 |
| 68 |
|
| 69 |
enum HeapType {GENERAL_HEAP, /**< Heap with alloc/free mechanism */ |
| 70 |
SIMPLE_HEAP /**< Heap with mark/release mechanism*/ |
| 71 |
}; |
| 72 |
|
| 73 |
/****************************************************************************/ |
| 74 |
/****************************************************************************/ |
| 75 |
/** @name Defines and macros for the virtual heap management */ |
| 76 |
|
| 77 |
/** \brief That many blocks can be allocated */ |
| 78 |
#define MAXNBLOCKS 50 |
| 79 |
|
| 80 |
/** \brief Pass to init routine if no heap yet */ |
| 81 |
#define SIZE_UNKNOWN 0 |
| 82 |
|
| 83 |
/** \brief Ok return code for virtual heap mgmt*/ |
| 84 |
#define BHM_OK 0 |
| 85 |
|
| 86 |
/** \brief Return codes of DefineBlock */ |
| 87 |
enum {HEAP_FULL = 1, /**< Return code if storage exhausted */ |
| 88 |
BLOCK_DEFINED = 2, /**< Return code if block already defined*/ |
| 89 |
NO_FREE_BLOCK = 3 /**< Return code if no free block found */ |
| 90 |
}; |
| 91 |
|
| 92 |
/* return codes of FreeBlock */ |
| 93 |
/** \brief Return code if the block is not defined */ |
| 94 |
#define BLOCK_NOT_DEFINED 1 |
| 95 |
|
| 96 |
/* @} */ |
| 97 |
/****************************************************************************/ |
| 98 |
/* */ |
| 99 |
/* data structures exported by the corresponding source file */ |
| 100 |
/* */ |
| 101 |
/****************************************************************************/ |
| 102 |
|
| 103 |
typedef unsigned long MEM; |
| 104 |
|
| 105 |
/****************************************************************************/ |
| 106 |
/* structs and typedefs for the simple and general heap management */ |
| 107 |
/****************************************************************************/ |
| 108 |
|
| 109 |
typedef struct { |
| 110 |
enum HeapType type; |
| 111 |
MEM size; |
| 112 |
INT markKey; |
| 113 |
std::vector<void*> markedMemory[MARK_STACK_SIZE+1]; |
| 114 |
} HEAP; |
| 115 |
|
| 116 |
/****************************************************************************/ |
| 117 |
/* */ |
| 118 |
/* function declarations */ |
| 119 |
/* */ |
| 120 |
/****************************************************************************/ |
| 121 |
|
| 122 |
/** @name Functions for the simple and general heap management */ |
| 123 |
/* @{ */ |
| 124 |
HEAP *NewHeap (enum HeapType type, MEM size, void *buffer); |
| 125 |
void DisposeHeap (HEAP *theHeap); |
| 126 |
|
| 127 |
void *GetMem (HEAP *theHeap, MEM n); |
| 128 |
void *GetFreelistMemory (HEAP *theHeap, INT size); |
| 129 |
void DisposeMem (HEAP *theHeap, void *buffer); |
| 130 |
|
| 131 |
INT MarkTmpMem (HEAP *theHeap, INT *key); |
| 132 |
void *GetTmpMem (HEAP *theHeap, MEM n, INT key); |
| 133 |
INT ReleaseTmpMem (HEAP *theHeap, INT key); |
| 134 |
/* @} */ |
| 135 |
|
| 136 |
END_UG_NAMESPACE |
| 137 |
|
| 138 |
/** @} */ |
| 139 |
|
| 140 |
#endif |