4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
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
27 * Good ROcking Metal Altar for Chronical Sinners
33 static char *SRCID_memtab_h = "$Id$";
40 #ident "@(#) memtab.h 1.12 12/16/92"
41 #endif /* HAVE_IDENT */
44 * This module is intended for alloc(at)ing memory in one contiguous
45 * block, using only local references. All references within this block
46 * are made relative to the start of the block. This means that before
47 * using a pointer in this block, they must be reallocated, simply by
48 * adding the base address to the pointer value.
51 #define NOENTRY -1 /* Denotes a NULL pointer reference */
55 void *ref; /* The "physical" address of an entry */
56 void *handle; /* The associated handle */
61 int nref; /* The number of inserted references */
62 t_mref *refs; /* The inserted references and their handles */
63 int msize; /* The total size of the memory allocated sofar */
64 char *mtab; /* The allocated memory (one contiguous block) */
67 extern void init_memtab(t_memtab *mtab);
69 * Initialises the struct, should be called before any other action
70 * The function init_memtab() will initialise a struct which can be
71 * extended by successive invokations of put_memtab().
74 extern void dispose_memtab(t_memtab *mtab);
76 * Disposes all the memory allocated for the struct. After this
77 * any reference within the block may become invalid (depends on
78 * the definition of the free() call).
81 extern void *put_memtab(t_memtab *mtab,int size,void *ref);
83 * The function put_memtab() returns a handle to the memory block
84 * specified by pointer ref and size bytes. If the address was inserted
85 * before in the struct, this (previous) handle will be returned else
86 * the struct will be extended, a new handle will be created and the
87 * data will be copied into the struct. Note that the returned handle
88 * is actually the offset of the copied block within the struct.
89 * NULL pointers and null sizes will return a handle that will convert
90 * to NULL after invokation of get_memtab(). Note that after every
91 * invokation absolute addresses, got before from get_memtab() might
92 * have changed due to a move within the reallocation.
95 extern void *get_memtab(t_memtab *mtab,void *handle);
97 * Returns the (physical) address corresponding to the specified handle.
98 * Handle should be a value returned by put_memtab(). When invoked
99 * with NULL for handle, get_memtab() returns the base address of
100 * the allocated block.
103 long wr_memtab(FILE *fp,t_memtab *mtab);
105 * Writes the referenced contents of the struct to the file specified
106 * by fp. The function wr_memtab() returnes the number of bytes written.
109 void *rd_memtab(FILE *fp,int size,t_memtab *mtab);
111 * Extends the struct by reading size bytes from the file specified
112 * by fp. The function rd_memtab() will return a handle to the read
116 #endif /* _memtab_h */