changed reading hint
[gromacs/adressmacs.git] / include / memtab.h
blobc94b243bdf6d49239fc747deb2d2ef672a40b8e1
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Good ROcking Metal Altar for Chronical Sinners
30 #ifndef _memtab_h
31 #define _memtab_h
33 static char *SRCID_memtab_h = "$Id$";
35 #ifdef HAVE_IDENT
36 #ident "@(#) memtab.h 1.12 12/16/92"
37 #endif /* HAVE_IDENT */
40 * This module is intended for alloc(at)ing memory in one contiguous
41 * block, using only local references. All references within this block
42 * are made relative to the start of the block. This means that before
43 * using a pointer in this block, they must be reallocated, simply by
44 * adding the base address to the pointer value.
47 #define NOENTRY -1 /* Denotes a NULL pointer reference */
49 typedef struct
51 void *ref; /* The "physical" address of an entry */
52 void *handle; /* The associated handle */
53 } t_mref;
55 typedef struct
57 int nref; /* The number of inserted references */
58 t_mref *refs; /* The inserted references and their handles */
59 int msize; /* The total size of the memory allocated sofar */
60 char *mtab; /* The allocated memory (one contiguous block) */
61 } t_memtab;
63 extern void init_memtab(t_memtab *mtab);
65 * Initialises the struct, should be called before any other action
66 * The function init_memtab() will initialise a struct which can be
67 * extended by successive invokations of put_memtab().
70 extern void dispose_memtab(t_memtab *mtab);
72 * Disposes all the memory allocated for the struct. After this
73 * any reference within the block may become invalid (depends on
74 * the definition of the free() call).
77 extern void *put_memtab(t_memtab *mtab,int size,void *ref);
79 * The function put_memtab() returns a handle to the memory block
80 * specified by pointer ref and size bytes. If the address was inserted
81 * before in the struct, this (previous) handle will be returned else
82 * the struct will be extended, a new handle will be created and the
83 * data will be copied into the struct. Note that the returned handle
84 * is actually the offset of the copied block within the struct.
85 * NULL pointers and null sizes will return a handle that will convert
86 * to NULL after invokation of get_memtab(). Note that after every
87 * invokation absolute addresses, got before from get_memtab() might
88 * have changed due to a move within the reallocation.
91 extern void *get_memtab(t_memtab *mtab,void *handle);
93 * Returns the (physical) address corresponding to the specified handle.
94 * Handle should be a value returned by put_memtab(). When invoked
95 * with NULL for handle, get_memtab() returns the base address of
96 * the allocated block.
99 long wr_memtab(FILE *fp,t_memtab *mtab);
101 * Writes the referenced contents of the struct to the file specified
102 * by fp. The function wr_memtab() returnes the number of bytes written.
105 void *rd_memtab(FILE *fp,int size,t_memtab *mtab);
107 * Extends the struct by reading size bytes from the file specified
108 * by fp. The function rd_memtab() will return a handle to the read
109 * block.
112 #endif /* _memtab_h */