Loading...
Searching...
No Matches
glplib.h
Go to the documentation of this file.
/* glplib.h */
/*----------------------------------------------------------------------
-- Copyright (C) 2000, 2001, 2002 Andrew Makhorin <mao@mai2.rcnet.ru>,
-- Department for Applied Informatics, Moscow Aviation
-- Institute, Moscow, Russia. All rights reserved.
--
-- This file is a part of GLPK (GNU Linear Programming Kit).
--
-- Licensed under the Eclipse Public License (EPL) by permission of the
-- author for inclusion in the DyLP LP distribution.
----------------------------------------------------------------------*/
/*
@(#)glplib.h 1.1 10/18/02
svn/cvs: $Id: glplib.h 407 2010-12-31 20:48:48Z lou $
*/
#ifndef _GLPLIB_H
#define _GLPLIB_H
#define save_pointer dy_glp_save_pointer
#define read_pointer dy_glp_read_pointer
#define init_lib_env dy_glp_init_lib_env
#define get_env_ptr dy_glp_get_env_ptr
#define free_lib_env dy_glp_free_lib_env
#define print dy_glp_print
#define fault dy_glp_fault
#define _insist dy_glp_insist
#define watch dy_glp_watch
#define umalloc dy_glp_umalloc
#define ucalloc dy_glp_ucalloc
#define ufree dy_glp_ufree
#define create_pool dy_glp_create_pool
#define get_atom dy_glp_get_atom
#define free_atom dy_glp_free_atom
#define get_atomv dy_glp_get_atomv
#define clear_pool dy_glp_clear_pool
#define delete_pool dy_glp_delete_pool
extern void save_pointer(void *ptr);
/* save a pointer */
extern void *read_pointer(void);
/* obtain a pointer */
typedef struct ENV ENV;
typedef struct MEM MEM;
struct ENV
{ /* library environmental block */
MEM *mem_ptr;
/* pointer to the linked list of allocated memory blocks */
int mem_limit;
/* maximal amount of memory (in bytes) available for dynamic
allocation */
int mem_total;
/* total amount of currently allocated memory (in bytes; is the
sum of the size fields over all memory block descriptors) */
int mem_tpeak;
/* peak value of mem_total */
int mem_count;
/* total number of currently allocated memory blocks */
int mem_cpeak;
/* peak value of mem_count */
};
extern int init_lib_env(void);
/* initialize library environment */
extern ENV *get_env_ptr(void);
/* obtain a pointer to the environmental block */
extern int free_lib_env(void);
/* deinitialize library environment */
extern void print(const char *fmt, ...);
/* print informative message */
extern void fault(const char *fmt, ...);
/* print error message and terminate program execution */
#define insist(expr) \
((void)((expr) || (_insist(#expr, __FILE__, __LINE__), 1)))
extern void _insist(const char *expr, const char *file, int line);
/* check for logical condition */
extern double watch(void);
/* take reading of stop-watch */
/* some processors need data to be properly aligned; the align_boundary
macro defines the boundary which should fit for all data types; the
align_datasize macro allows enlarging size of data item in order the
immediately following data of any type should be properly aligned */
#define align_boundary sizeof(double)
#define align_datasize(size) \
((((size) + (align_boundary - 1)) / align_boundary) * align_boundary)
struct MEM
{ /* memory block descriptor */
int size;
/* size of block (in bytes, including descriptor) */
int flag;
/* descriptor flag */
MEM *prev;
/* pointer to descriptor of the previous block */
MEM *next;
/* pointer to descriptor of the next block */
/* actual data start here (there may be a "hole" between the next
field and actual data because of data alignment) */
};
extern void *umalloc(int size);
/* allocate memory block */
extern void *ucalloc(int nmemb, int size);
/* allocate memory block */
extern void ufree(void *ptr);
/* free memory block */
typedef struct POOL POOL;
struct POOL
{ /* memory pool (a set of atoms) */
int size;
/* size of each atom in bytes (1 <= size <= 256); if size = 0,
different atoms may have different sizes */
void *avail;
/* pointer to the linked list of free atoms */
void *link;
/* pointer to the linked list of allocated blocks (it points to
the last recently allocated block) */
int used;
/* number of bytes used in the last allocated block */
void *stock;
/* pointer to the linked list of free blocks */
int count;
/* total number of allocated atoms */
};
extern POOL *create_pool(int size);
/* create memory pool */
extern void *get_atom(POOL *pool);
/* allocate atom of fixed size */
extern void free_atom(POOL *pool, void *ptr);
/* free an atom */
extern void *get_atomv(POOL *pool, int size);
/* allocate atom of variable size */
extern void clear_pool(POOL *pool);
/* free all atoms */
extern void delete_pool(POOL *pool);
/* delete memory pool */
#endif
/* eof */
create_pool
#define create_pool
Definition glplib.h:37
save_pointer
#define save_pointer
Definition glplib.h:21
get_env_ptr
#define get_env_ptr
Definition glplib.h:25
free_atom
#define free_atom
Definition glplib.h:39
free_lib_env
#define free_lib_env
Definition glplib.h:26
umalloc
#define umalloc
Definition glplib.h:33
fault
#define fault
Definition glplib.h:29
init_lib_env
#define init_lib_env
Definition glplib.h:24
get_atom
#define get_atom
Definition glplib.h:38
delete_pool
#define delete_pool
Definition glplib.h:42
ucalloc
#define ucalloc
Definition glplib.h:34
ufree
#define ufree
Definition glplib.h:35
get_atomv
#define get_atomv
Definition glplib.h:40
clear_pool
#define clear_pool
Definition glplib.h:41
_insist
#define _insist
Definition glplib.h:30
print
#define print
Definition glplib.h:28
watch
#define watch
Definition glplib.h:31
read_pointer
#define read_pointer
Definition glplib.h:22
ENV
Definition glplib.h:54
ENV::mem_tpeak
int mem_tpeak
Definition glplib.h:63
ENV::mem_total
int mem_total
Definition glplib.h:60
ENV::mem_ptr
MEM * mem_ptr
Definition glplib.h:55
ENV::mem_limit
int mem_limit
Definition glplib.h:57
ENV::mem_count
int mem_count
Definition glplib.h:65
ENV::mem_cpeak
int mem_cpeak
Definition glplib.h:67
MEM
Definition glplib.h:106
MEM::size
int size
Definition glplib.h:107
MEM::next
MEM * next
Definition glplib.h:113
MEM::flag
int flag
Definition glplib.h:109
MEM::prev
MEM * prev
Definition glplib.h:111
POOL
Definition glplib.h:131
POOL::stock
void * stock
Definition glplib.h:142
POOL::size
int size
Definition glplib.h:132
POOL::link
void * link
Definition glplib.h:137
POOL::count
int count
Definition glplib.h:144
POOL::avail
void * avail
Definition glplib.h:135
POOL::used
int used
Definition glplib.h:140