00001 /* glplib.h */ 00002 00003 /*---------------------------------------------------------------------- 00004 -- Copyright (C) 2000, 2001, 2002 Andrew Makhorin <mao@mai2.rcnet.ru>, 00005 -- Department for Applied Informatics, Moscow Aviation 00006 -- Institute, Moscow, Russia. All rights reserved. 00007 -- 00008 -- This file is a part of GLPK (GNU Linear Programming Kit). 00009 -- 00010 -- GLPK is free software; you can redistribute it and/or modify it 00011 -- under the terms of the GNU General Public License as published by 00012 -- the Free Software Foundation; either version 2, or (at your option) 00013 -- any later version. 00014 -- 00015 -- GLPK is distributed in the hope that it will be useful, but WITHOUT 00016 -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00017 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00018 -- License for more details. 00019 -- 00020 -- You should have received a copy of the GNU General Public License 00021 -- along with GLPK; see the file COPYING. If not, write to the Free 00022 -- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00023 -- 02111-1307, USA. 00024 ----------------------------------------------------------------------*/ 00025 /* 00026 @(#)glplib.h 1.1 10/18/02 00027 svn/cvs: $Id: glplib.h 71 2006-06-09 04:21:15Z andreasw $ 00028 */ 00029 00030 #ifndef _GLPLIB_H 00031 #define _GLPLIB_H 00032 00033 #define save_pointer _glp_save_pointer 00034 #define read_pointer _glp_read_pointer 00035 00036 #define init_lib_env _glp_init_lib_env 00037 #define get_env_ptr _glp_get_env_ptr 00038 #define free_lib_env _glp_free_lib_env 00039 00040 #define print _glp_print 00041 #define fault _glp_fault 00042 #define _insist _glp_insist 00043 #define watch _glp_watch 00044 00045 #define umalloc _glp_umalloc 00046 #define ucalloc _glp_ucalloc 00047 #define ufree _glp_ufree 00048 00049 #define create_pool _glp_create_pool 00050 #define get_atom _glp_get_atom 00051 #define free_atom _glp_free_atom 00052 #define get_atomv _glp_get_atomv 00053 #define clear_pool _glp_clear_pool 00054 #define delete_pool _glp_delete_pool 00055 00056 extern void save_pointer(void *ptr); 00057 /* save a pointer */ 00058 00059 extern void *read_pointer(void); 00060 /* obtain a pointer */ 00061 00062 typedef struct ENV ENV; 00063 typedef struct MEM MEM; 00064 00065 struct ENV 00066 { /* library environmental block */ 00067 MEM *mem_ptr; 00068 /* pointer to the linked list of allocated memory blocks */ 00069 int mem_limit; 00070 /* maximal amount of memory (in bytes) available for dynamic 00071 allocation */ 00072 int mem_total; 00073 /* total amount of currently allocated memory (in bytes; is the 00074 sum of the size fields over all memory block descriptors) */ 00075 int mem_tpeak; 00076 /* peak value of mem_total */ 00077 int mem_count; 00078 /* total number of currently allocated memory blocks */ 00079 int mem_cpeak; 00080 /* peak value of mem_count */ 00081 }; 00082 00083 extern int init_lib_env(void); 00084 /* initialize library environment */ 00085 00086 extern ENV *get_env_ptr(void); 00087 /* obtain a pointer to the environmental block */ 00088 00089 extern int free_lib_env(void); 00090 /* deinitialize library environment */ 00091 00092 extern void print(const char *fmt, ...); 00093 /* print informative message */ 00094 00095 extern void fault(const char *fmt, ...); 00096 /* print error message and terminate program execution */ 00097 00098 #define insist(expr) \ 00099 ((void)((expr) || (_insist(#expr, __FILE__, __LINE__), 1))) 00100 00101 extern void _insist(const char *expr, const char *file, int line); 00102 /* check for logical condition */ 00103 00104 extern double watch(void); 00105 /* take reading of stop-watch */ 00106 00107 /* some processors need data to be properly aligned; the align_boundary 00108 macro defines the boundary which should fit for all data types; the 00109 align_datasize macro allows enlarging size of data item in order the 00110 immediately following data of any type should be properly aligned */ 00111 00112 #define align_boundary sizeof(double) 00113 00114 #define align_datasize(size) \ 00115 ((((size) + (align_boundary - 1)) / align_boundary) * align_boundary) 00116 00117 struct MEM 00118 { /* memory block descriptor */ 00119 int size; 00120 /* size of block (in bytes, including descriptor) */ 00121 int flag; 00122 /* descriptor flag */ 00123 MEM *prev; 00124 /* pointer to descriptor of the previous block */ 00125 MEM *next; 00126 /* pointer to descriptor of the next block */ 00127 /* actual data start here (there may be a "hole" between the next 00128 field and actual data because of data alignment) */ 00129 }; 00130 00131 extern void *umalloc(int size); 00132 /* allocate memory block */ 00133 00134 extern void *ucalloc(int nmemb, int size); 00135 /* allocate memory block */ 00136 00137 extern void ufree(void *ptr); 00138 /* free memory block */ 00139 00140 typedef struct POOL POOL; 00141 00142 struct POOL 00143 { /* memory pool (a set of atoms) */ 00144 int size; 00145 /* size of each atom in bytes (1 <= size <= 256); if size = 0, 00146 different atoms may have different sizes */ 00147 void *avail; 00148 /* pointer to the linked list of free atoms */ 00149 void *link; 00150 /* pointer to the linked list of allocated blocks (it points to 00151 the last recently allocated block) */ 00152 int used; 00153 /* number of bytes used in the last allocated block */ 00154 void *stock; 00155 /* pointer to the linked list of free blocks */ 00156 int count; 00157 /* total number of allocated atoms */ 00158 }; 00159 00160 extern POOL *create_pool(int size); 00161 /* create memory pool */ 00162 00163 extern void *get_atom(POOL *pool); 00164 /* allocate atom of fixed size */ 00165 00166 extern void free_atom(POOL *pool, void *ptr); 00167 /* free an atom */ 00168 00169 extern void *get_atomv(POOL *pool, int size); 00170 /* allocate atom of variable size */ 00171 00172 extern void clear_pool(POOL *pool); 00173 /* free all atoms */ 00174 00175 extern void delete_pool(POOL *pool); 00176 /* delete memory pool */ 00177 00178 #endif 00179 00180 /* eof */