DyLP 1.10.4
Loading...
Searching...
No Matches
glplib.h
Go to the documentation of this file.
1/* glplib.h */
2
3/*----------------------------------------------------------------------
4-- Copyright (C) 2000, 2001, 2002 Andrew Makhorin <mao@mai2.rcnet.ru>,
5-- Department for Applied Informatics, Moscow Aviation
6-- Institute, Moscow, Russia. All rights reserved.
7--
8-- This file is a part of GLPK (GNU Linear Programming Kit).
9--
10-- Licensed under the Eclipse Public License (EPL) by permission of the
11-- author for inclusion in the DyLP LP distribution.
12----------------------------------------------------------------------*/
13/*
14 @(#)glplib.h 1.1 10/18/02
15 svn/cvs: $Id: glplib.h 407 2010-12-31 20:48:48Z lou $
16*/
17
18#ifndef _GLPLIB_H
19#define _GLPLIB_H
20
21#define save_pointer dy_glp_save_pointer
22#define read_pointer dy_glp_read_pointer
23
24#define init_lib_env dy_glp_init_lib_env
25#define get_env_ptr dy_glp_get_env_ptr
26#define free_lib_env dy_glp_free_lib_env
27
28#define print dy_glp_print
29#define fault dy_glp_fault
30#define _insist dy_glp_insist
31#define watch dy_glp_watch
32
33#define umalloc dy_glp_umalloc
34#define ucalloc dy_glp_ucalloc
35#define ufree dy_glp_ufree
36
37#define create_pool dy_glp_create_pool
38#define get_atom dy_glp_get_atom
39#define free_atom dy_glp_free_atom
40#define get_atomv dy_glp_get_atomv
41#define clear_pool dy_glp_clear_pool
42#define delete_pool dy_glp_delete_pool
43
44extern void save_pointer(void *ptr);
45/* save a pointer */
46
47extern void *read_pointer(void);
48/* obtain a pointer */
49
50typedef struct ENV ENV;
51typedef struct MEM MEM;
52
53struct ENV
54{ /* library environmental block */
56 /* pointer to the linked list of allocated memory blocks */
58 /* maximal amount of memory (in bytes) available for dynamic
59 allocation */
61 /* total amount of currently allocated memory (in bytes; is the
62 sum of the size fields over all memory block descriptors) */
64 /* peak value of mem_total */
66 /* total number of currently allocated memory blocks */
68 /* peak value of mem_count */
69};
70
71extern int init_lib_env(void);
72/* initialize library environment */
73
74extern ENV *get_env_ptr(void);
75/* obtain a pointer to the environmental block */
76
77extern int free_lib_env(void);
78/* deinitialize library environment */
79
80extern void print(const char *fmt, ...);
81/* print informative message */
82
83extern void fault(const char *fmt, ...);
84/* print error message and terminate program execution */
85
86#define insist(expr) \
87((void)((expr) || (_insist(#expr, __FILE__, __LINE__), 1)))
88
89extern void _insist(const char *expr, const char *file, int line);
90/* check for logical condition */
91
92extern double watch(void);
93/* take reading of stop-watch */
94
95/* some processors need data to be properly aligned; the align_boundary
96 macro defines the boundary which should fit for all data types; the
97 align_datasize macro allows enlarging size of data item in order the
98 immediately following data of any type should be properly aligned */
99
100#define align_boundary sizeof(double)
101
102#define align_datasize(size) \
103((((size) + (align_boundary - 1)) / align_boundary) * align_boundary)
104
105struct MEM
106{ /* memory block descriptor */
107 int size;
108 /* size of block (in bytes, including descriptor) */
109 int flag;
110 /* descriptor flag */
112 /* pointer to descriptor of the previous block */
114 /* pointer to descriptor of the next block */
115 /* actual data start here (there may be a "hole" between the next
116 field and actual data because of data alignment) */
117};
118
119extern void *umalloc(int size);
120/* allocate memory block */
121
122extern void *ucalloc(int nmemb, int size);
123/* allocate memory block */
124
125extern void ufree(void *ptr);
126/* free memory block */
127
128typedef struct POOL POOL;
129
130struct POOL
131{ /* memory pool (a set of atoms) */
132 int size;
133 /* size of each atom in bytes (1 <= size <= 256); if size = 0,
134 different atoms may have different sizes */
135 void *avail;
136 /* pointer to the linked list of free atoms */
137 void *link;
138 /* pointer to the linked list of allocated blocks (it points to
139 the last recently allocated block) */
140 int used;
141 /* number of bytes used in the last allocated block */
142 void *stock;
143 /* pointer to the linked list of free blocks */
144 int count;
145 /* total number of allocated atoms */
146};
147
148extern POOL *create_pool(int size);
149/* create memory pool */
150
151extern void *get_atom(POOL *pool);
152/* allocate atom of fixed size */
153
154extern void free_atom(POOL *pool, void *ptr);
155/* free an atom */
156
157extern void *get_atomv(POOL *pool, int size);
158/* allocate atom of variable size */
159
160extern void clear_pool(POOL *pool);
161/* free all atoms */
162
163extern void delete_pool(POOL *pool);
164/* delete memory pool */
165
166#endif
167
168/* eof */
#define create_pool
Definition glplib.h:37
#define save_pointer
Definition glplib.h:21
#define get_env_ptr
Definition glplib.h:25
#define free_atom
Definition glplib.h:39
#define free_lib_env
Definition glplib.h:26
#define umalloc
Definition glplib.h:33
#define fault
Definition glplib.h:29
#define init_lib_env
Definition glplib.h:24
#define get_atom
Definition glplib.h:38
#define delete_pool
Definition glplib.h:42
#define ucalloc
Definition glplib.h:34
#define ufree
Definition glplib.h:35
#define get_atomv
Definition glplib.h:40
#define clear_pool
Definition glplib.h:41
#define _insist
Definition glplib.h:30
#define print
Definition glplib.h:28
#define watch
Definition glplib.h:31
#define read_pointer
Definition glplib.h:22
Definition glplib.h:54
int mem_tpeak
Definition glplib.h:63
int mem_total
Definition glplib.h:60
MEM * mem_ptr
Definition glplib.h:55
int mem_limit
Definition glplib.h:57
int mem_count
Definition glplib.h:65
int mem_cpeak
Definition glplib.h:67
Definition glplib.h:106
int size
Definition glplib.h:107
MEM * next
Definition glplib.h:113
int flag
Definition glplib.h:109
MEM * prev
Definition glplib.h:111
Definition glplib.h:131
void * stock
Definition glplib.h:142
int size
Definition glplib.h:132
void * link
Definition glplib.h:137
int count
Definition glplib.h:144
void * avail
Definition glplib.h:135
int used
Definition glplib.h:140