File: memory.h

package info (click to toggle)
sift 6.2.1-2
  • links: PTS, VCS
  • area: non-free
  • in suites: sid
  • size: 4,784 kB
  • sloc: ansic: 18,272; perl: 219; csh: 164; makefile: 152
file content (141 lines) | stat: -rwxr-xr-x 4,867 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* (C) Copyright 1993-7, Fred Hutchinson Cancer Research Center */
/* Use, modification or distribution of these programs is subject to */
/* the terms of the non-commercial licensing agreement in license.h. */

/* memory.h: Memory management functions and macros. */
/* Written by: Bill Alford */
/* Change log information is at the end of the file. */

#ifndef MEMORY_H_
#define MEMORY_H_

/*
 * Exported variables and data structures
 */

#define REPORT_DECREASE_AMOUNT  1  /* amount to decrease NumberToReport by */
				   /* if there is not enough room */
				   /* NOTE: MUST be greater than zero */


/*
 * Exported macros
 */

/********************************************************************
 * This macro is supposed to enclose malloc, calloc, and realloc 
 * assignments.  For example:                             
 * CheckMem(                                              
 *          new_block = (Block *) malloc(sizeof(Block))   
 *          );                                            
 * 
 * Note that if using around a realloc you should be assigning the new 
 * memory pointer to a temporary variable so that you do not loose the 
 * original pointer to memory if the CheckMem macro has to loop.
 * For example:                          
 *  Residue *tmp_ptr;  
 *  ...  
 *  CheckMem(                                                        
 *           tmp_ptr = (Residue *) realloc(seq->sequence,            
 *                                         seq->max_length *   
 *                                         sizeof(Residue))    
 *           );                                                      
 *  seq->sequence = tmp_ptr;
 * 
 ********************************************************************/

#ifndef NO_RECLAIM
#define CheckMem(A)		           \
{                                          \
  while(((A) == NULL) &&                   \
	((reclaim_space()) ?               \
	 TRUE :                            \
	 (sprintf(ErrorBuffer,             \
		 "Unable to recover enough memory to continue.  Aborting.\n"),\
	  ErrorReport(FATAL_ERR_LVL),      \
	  FALSE)                           \
	 )                                 \
	);                                 \
}
#else
#define CheckMem(A)                        \
{                                          \
  while(((A) == NULL) &&                   \
        (sprintf(ErrorBuffer,              \
                 "Unable to allocate memory.  Aborting.\n"),\
         ErrorReport(FATAL_ERR_LVL),       \
         FALSE)                            \
        );                                 \
}
#endif /* NO_RECLAIM */


/*
 * Exported functions
 */

/*
 * reclaim_space
 *   Tries to reclaim some of the allocated memory.  It tries to
 *   reclaim the memory from the various lists that are used by
 *   decreasing the elements that can be stored in the lists.
 *   NOTE: This function assumes that the searching has already begun.
 *         If that is not the case it will report that it was unable
 *         to get space because the list size and the NumberToReport
 *         will likely be zero.  This doesn't really matter much
 *         because if we have to reclaim space that early in the run, 
 *         there are problems.
 *   NOTE: Because of the SavedNodes list in the skiplist package many
 *         calls to reclaim_space may be needed before the free lists
 *         are filled and actual memory is freed.  This is not that
 *         big of a problem, considering that a balance will be
 *         reached with the nodes in the free lists.  The only time
 *         this would cause the Scores list size to reduce to zero is
 *         if there is so little memory that there can be only about
 *         20 scores in the list.  That amount of memory is about 100
 *         Kbytes. 
 *   Parameters: none
 *   Return codes: TRUE if it was able to get free some space, FALSE
 *                 if not.
 *   Error codes:  FALSE if it unable to get space.
 */

#ifndef NO_RECLAIM
extern Boolean reclaim_space();
#endif /* NO_RECLAIM */


/*
 * init_reclaim_space
 *   Sets up the reclaim_space function to call the passed function.
 *   Parameters:
 *     Boolean (*rec_func)(): The reclaiming function.
 *   Return codes: none.
 *   Error codes: none.
 */

extern void init_reclaim_space();


#endif /*  MEMORY_H_ */




/* Change log information follows. */
/* 
 * Revision 2.1021  1994/05/09  20:22:18  billa
 * Made the reclaim_space() function call the programmer supplied memory
 * recovery function rather than using the blimps specific code.
 *
 * Revision 2.1017  1994/04/27  02:29:29  billa
 * Removed RECLAIM_SPACE define.
 *
 * Revision 1.1000  1993/08/27  16:56:34  billa
 * Creation.  Added the function reclaim_space() and the macro CheckMem(A)
 * to handle the situation when there is no more memory to allocate.
 *
 */