/[ascend]/trunk/base/generic/utilities/ascMalloc.h
ViewVC logotype

Annotation of /trunk/base/generic/utilities/ascMalloc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (hide annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (14 years, 3 months ago) by johnpye
File MIME type: text/x-chdr
File size: 21013 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 johnpye 599 /* ASCEND modelling environment
2     Copyright (C) 2006 Carnegie Mellon University
3 aw0a 1
4 johnpye 599 This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2, or (at your option)
7     any later version.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place - Suite 330,
17     Boston, MA 02111-1307, USA.
18     *//** @file
19     ASCEND memory allocation & reporting routines.
20    
21     These functions provide tracking of memory events and assist
22     finding and debugging memory errors. Memory tracking options are
23     selected using the macros MALLOC_DEBUG and ALLOCATED_TESTS discussed
24     below. This allows the enhanced functionality to be used or turned
25     off as desired. This functionality adds considerable run-time overhead,
26     and so should generally be used for debugging purposes only. There are
27     also routines for reporting on the status of memory blocks as well as
28     for the memory manager itself.<br><br>
29    
30     To use the memory tracking features, you need to use the provided
31     allocation and deallocation functions (ascmalloc(), asccalloc(),
32     ascrealloc(), ascfree()). Direct calls to the corresponding system
33     routines will by-pass the memory manager and not be tracked. Memory
34     allocations which return NULL are not tracked or recorded.<br><br>
35    
36     This module also standardizes critical implementation-specific features
37     such as behavior when an allocation of zero bytes is requested
38     (see MOD_ASCMALLOC), and the behavior of realloc() under purify
39     (see MOD_REALLOC).<br><br>
40    
41     The following macros affect the compilation and run-time behavior
42     of Ascend memory management.
43    
44     <pre>
45     MOD_ASCMALLOC Forces the memory allocation functions to always
46     allocate at least 1 byte and return a non-NULL
47     pointer. This macro should be defined if your
48     allocator returns NULL when a zero-sized block is
49     requested (e.g. alpha or rs6000; Borland and Watcom
50     on Windows). It need not be defined if your
51     allocator returns a non-NULL pointer to a zero-length
52     block, saving you a few bytes of memory.
53    
54     MALLOC_DEBUG Causes all calls to memory allocation routines
55     to be tracked and logged to an output file.
56     This really slows down the memory management
57     system, and so should be used for debugging only.
58    
59     ALLOCATED_TESTS Forces a lot of extra assertions when defined
60     along with MALLOC_DEBUG.
61    
62     MOD_REALLOC If defined, ascreallocPURE() uses a homegrown
63     realloc() that behaves properly with purify.
64     This is more expensive, and should be used
65     for debugging only.
66    
67     Requires:
68     #include "utilities/ascConfig.h"
69     #include "utilities/ascPanic.h"
70     </pre>
71     *//*
72     by Tom Epperly
73     Created: 2/6/90
74     Version: $Revision: 1.2 $
75     Version control file: $RCSfile: ascMalloc.h,v $
76     Date last modified: $Date: 1997/07/18 11:44:50 $
77     Last modified by: $Author: mthomas $
78     */
79    
80 johnpye 67 #ifndef ASC_ASCMALLOC_H
81     #define ASC_ASCMALLOC_H
82 aw0a 1
83 johnpye 599 /* MALLOC_DEBUG may be defined in config.h... */
84     #include <utilities/config.h>
85 aw0a 1
86 jds 59 #ifdef MALLOC_DEBUG
87     # define ascstrdup(str) ascstrdupf_dbg(str)
88     #else
89     # define ascstrdup(str) ascstrdupf(str)
90     #endif
91 jds 54 /**<
92 jds 59 * Returns a new copy of string str.
93     * This is the ASCEND rendition of strdup(). The caller is
94     * responsible for deallocating the new string when finished
95     * using ascfree(). Returns NULL if str is NULL or memory
96     * cannot be allocated for the new copy. If MALLOC_DEBUG is
97     * defined, the allocation is tracked.
98     *
99     * @param str The 0-terminated string to copy.
100     * @return A new copy of str as a char *, or NULL if an error occurs.
101 aw0a 1 */
102    
103 johnpye 669 /**
104     Shorthand for creating pointers to newly allocated data of a given type
105     */
106     #define ASC_NEW(TYPE) (TYPE *)ascmalloc(sizeof(TYPE))
107    
108     #define ASC_NEW_CLEAR(TYPE) (TYPE *)asccalloc(1,sizeof(TYPE))
109    
110     /**
111     Shorthand for creating pointer to an array of newly allocated data of a
112     given type. 'ascmalloc' is used for the allocation.
113     */
114     #define ASC_NEW_ARRAY(TYPE,COUNT) (TYPE *)ascmalloc(sizeof(TYPE)*(COUNT))
115    
116     /**
117     Shorthand for creating a pointer to allocated data, using asccalloc (to zero
118     the allocated space).
119     */
120     #define ASC_NEW_ARRAY_CLEAR(TYPE,COUNT) (TYPE *)asccalloc(COUNT,sizeof(TYPE))
121    
122     /**
123     Shorthand for creating a pointer to an array of allocated data. If the
124     specified length is zero, no space is allocated, and a NULL is returned
125     instead.
126     */
127     #define ASC_NEW_ARRAY_OR_NULL(TYPE,COUNT) \
128     ((COUNT)>0 ? ASC_NEW_ARRAY(TYPE,COUNT) : NULL)
129    
130     #define ASC_NEW_ARRAY_OR_NULL_CLEAR(TYPE,COUNT) \
131     ((COUNT)>0 ? ASC_NEW_ARRAY_CLEAR(TYPE,COUNT) : NULL)
132    
133     /* regular expressions for fixing up mallocs (in regexxer)
134     \(([^\*\)]+) ?\*\)\s*ascmalloc\(sizeof\(\1\)\s*\*\s*([a-zA-Z][a-zA-Z_0-9]*)\)
135     \(([^\*\)]+) ?\*\)\s*asccalloc\(([a-zA-Z][a-zA-Z_0-9]*)\s*,\s*sizeof\(\1\)\s*\)
136     */
137    
138     #define ASC_FREE(PTR) ascfree(PTR)
139    
140 johnpye 600 ASC_DLLSPEC(char *) ascstrdupf(CONST char *str);
141 jds 54 /**<
142 jds 59 * Implementation function for ascstrdup() if MALLOC_DEBUG
143 johnpye 599 * is not defined. Do not call this function directly - use
144 jds 59 * ascstrdup() instead.
145 aw0a 1 */
146    
147 johnpye 639 ASC_DLLSPEC(char *) ascstrdupf_dbg(CONST char *str);
148 jds 54 /**<
149 jds 59 * Implementation function for ascstrdup() if MALLOC_DEBUG
150     * is defined. Do not call this function directly - define
151     * MALLOC_DEBUG and use ascstrdup() instead.
152 aw0a 1 */
153    
154 johnpye 593 ASC_DLLSPEC(char *) asc_memcpy(char *dest, char *src, size_t n);
155 jds 54 /**<
156 jds 59 * Copies n bytes from memory address src to dest.
157     * This version of memcpy handles overlapping memory ranges
158 johnpye 599 * properly. It could be more efficient internally. As it is,
159     * it moves data a char at a time. Unless n is 0, neither dest
160 jds 100 * nor src may be NULL (checked by asc_assertion).
161 jds 59 *
162     * @param dest Pointer to address to which to copy (non-NULL).
163     * @param src Pointer to address from which to copy (non-NULL).
164     * @param n Number of bytes to copy.
165     * @return Returns dest.
166 aw0a 1 */
167    
168 jds 59 #ifndef MOD_REALLOC
169     # define ascreallocPURE(ptr,nold,nnew) ascrealloc((ptr),(nnew))
170     #else
171     # ifdef MALLOC_DEBUG
172     # define ascreallocPURE(ptr,nold,nnew) ascreallocPUREF_dbg((ptr),(nold),(nnew))
173     # else
174     # define ascreallocPURE(ptr,nold,nnew) ascreallocPUREF((ptr),(nold),(nnew))
175     # endif
176     #endif
177     /**<
178     * purify realloc() function for debugging purposes.
179     * In some OS, realloc() fools purify into thinking there
180     * is a memory leak. If MOD_REALLOC is defined at compile
181 johnpye 599 * time for all software referencing this header, then all
182 jds 59 * calls to ascreallocPURE() will use a homegrown realloc
183 johnpye 599 * that does not fool purify. Leaks of memory reported
184     * around realloc() when MOD_REALLOC is defined should be
185 jds 59 * real leaks and not OS noise.<br><br>
186 aw0a 1 *
187 johnpye 599 * The custom function is somewhat more expensive than most
188 jds 59 * system-supplied realloc()'s, so should only be used for
189 johnpye 599 * debugging. Note that ascreallocPURE() will provide memory
190 jds 59 * event tracking if MALLOC_DEBUG is also defined when this
191     * header is included.
192 aw0a 1 *
193 jds 59 * @see ascreallocPUREF()
194     * @param ptr Pointer to the memory block to reallocate.
195     * @param nold Old block size in bytes.
196     * @param nnew New block size in bytes.
197     * @return A pointer to the new memory block, or NULL if an error occurred.
198 aw0a 1 */
199    
200 jds 59 extern char *ascreallocPUREF(char *ptr, size_t oldbytes, size_t newbytes);
201     /**<
202     * Implementation function for release version of ascreallocPURE().
203     * Do not call this function directly - use ascreallocPURE()
204     * (by #defining MOD_REALLOC) instead. This version does not have
205 johnpye 599 * its memory tracked. This is a custom realloc() which behaves
206     * properly with purify. It bypasses the standard realloc() function.
207 jds 59 * The caller must indicate the old size of the memory region.
208     *
209     * @param ptr Pointer to the memory block to reallocate.
210     * @param oldbytes Old block size in bytes.
211     * @param newbytes New block size in bytes.
212     * @return A pointer to the new memory block, or NULL if an error occurred.
213 aw0a 1 */
214    
215 jds 59 extern char *ascreallocPUREF_dbg(char *ptr, size_t oldbytes, size_t newbytes);
216     /**<
217     * Implementation function for debug version of ascreallocPURE().
218     * Do not call this function directly - use ascreallocPURE()
219     * (by #defining MOD_REALLOC and MALLOC_DEBUG) instead. This version
220     * has it's allocations tracked by the memory manager. This is
221     * a custom realloc() which behaves properly with purify. It
222     * bypasses the standard realloc() function. The caller must indicate
223     * the old size of the memory region.
224     *
225     * @param ptr Pointer to the memory block to reallocate.
226     * @param oldbytes Old block size in bytes.
227     * @param newbytes New block size in bytes.
228     * @return A pointer to the new memory block, or NULL if an error occurred.
229 aw0a 1 */
230 jds 59
231     #ifdef MALLOC_DEBUG
232     # define ascstatus(msg) ascstatusf(msg)
233 aw0a 1 #else
234 jds 59 # define ascstatus(msg)
235 aw0a 1 #endif
236 jds 59 /**<
237     * Prints a summary of the memory manager status (iff MALLOC_DEBUG
238     * is defined) The msg is first printed, followed by a newline and
239     * then the summary memory report. These are printed both to the
240     * memory log file, as well as to the screen. If MALLOC_DEBUG is
241     * not defined, then nothing is printed.
242     *
243     * @see ascstatus_detail(), ascshutdown()
244     * @param msg The message to print before the summary report.
245     */
246 aw0a 1
247 jds 59 extern void ascstatusf(CONST char *msg);
248     /**<
249     * Implementation function for ascstatus() if MALLOC_DEBUG
250     * is defined. Do not call this function directly - define
251     * MALLOC_DEBUG and use ascstatus() instead.
252 aw0a 1 */
253 jds 59
254 aw0a 1 #ifdef MALLOC_DEBUG
255 jds 59 # define ascstatus_detail(msg) ascstatus_detailf(msg)
256     #else
257     # define ascstatus_detail(msg)
258     #endif
259     /**<
260     * Prints a more detailed report of the memory manager status (iff
261     * MALLOC_DEBUG is defined) The msg is first printed, followed by
262     * a newline and then the memory report. This report includes both
263     * the summary information printed by ascstatus(), as well as a listing
264     * of memory blocks currently allocated. These are printed both to the
265     * memory log file, as well as to the screen. If MALLOC_DEBUG is
266     * not defined, then nothing is printed.
267     *
268     * @see ascstatus(), ascshutdown()
269     * @param msg The message to print before the detail report.
270     */
271 aw0a 1
272 jds 59 extern void ascstatus_detailf(CONST char *msg);
273     /**<
274     * Implementation function for ascstatus_detail() if MALLOC_DEBUG
275     * is defined. Do not call this function directly - define
276     * MALLOC_DEBUG and use ascstatus_detail() instead.
277     */
278 aw0a 1
279 jds 59 #ifdef MALLOC_DEBUG
280     # define ascshutdown(msg) ascshutdownf(msg)
281     #else
282     # define ascshutdown(msg)
283     #endif
284     /**<
285     * Prints a detailed report of the memory manager status and cleans
286     * up after memory logging (iff MALLOC_DEBUG is defined). The
287     * reporting is the same as ascstatus_detail(). After this function
288     * is called, subsequent allocation/deallocation activity will be
289     * logged in a different log file than previously. If MALLOC_DEBUG
290     * is not defined, then this function does nothing.
291     *
292     * @see ascstatus(), ascstatus_detail()
293     * @param msg The message to print before the detail report.
294     */
295 aw0a 1
296 johnpye 600 ASC_DLLSPEC(void) ascshutdownf(CONST char *msg);
297 jds 59 /**<
298     * Implementation function for ascshutdown() if MALLOC_DEBUG
299     * is defined. Do not call this function directly - define
300     * MALLOC_DEBUG and use ascshutdown() instead.
301     */
302 aw0a 1
303 jds 59 #ifdef MALLOC_DEBUG
304     # define ascmeminuse() ascmeminusef()
305     #else
306     # define ascmeminuse() (0)
307     #endif
308 aw0a 1
309 johnpye 600 ASC_DLLSPEC(unsigned long) ascmeminusef(void);
310 jds 59 /**<
311     * Returns the current total amount of allocated memory (iff
312     * MALLOC_DEBUG is #defined). If MALLOC_DEBUG is not #defined,
313     * the return value is 0 regardless of the actual amount of
314     * allocated memory.
315     */
316 aw0a 1
317 jds 59 #ifdef MOD_ASCMALLOC
318     # define AT_LEAST_1(x) MAX((x),1)
319     #else
320     # define AT_LEAST_1(x) (x)
321     #endif
322     /**<
323     * Macro to ensure at least 1 byte is requested when MOD_ASCMALLOC
324     * is defined. Requires a define for MAX(), which is located in
325     * utilities/ascConfig.h.
326     */
327 aw0a 1
328 jds 59 #ifdef MALLOC_DEBUG
329     # define asccalloc(nelem, size) \
330     asccallocf(AT_LEAST_1(nelem), (size), __FILE__, __LINE__)
331     #else
332     # define asccalloc(nelem,size) calloc(AT_LEAST_1(nelem),(size))
333     #endif
334 jds 54 /**<
335 jds 59 * ASCEND calloc() function.
336     * If MALLOC_DEBUG is defined, the allocation is tracked.
337     * If not, then the standard system calloc() is used.
338     *
339     * @see asccallocf()
340     * @param nelem size_t, number of elements to allocate.
341     * @param size size_t, size of each element.
342     * @return A (void *) to the newly-allocated block, or NULL on error.
343 aw0a 1 */
344    
345 johnpye 600 ASC_DLLSPEC(VOIDPTR) asccallocf(size_t nelem, size_t elsize,
346 jds 59 CONST char *file, int line);
347 jds 54 /**<
348 jds 59 * Implementation function for asccalloc() when MALLOC_DEBUG
349     * is defined. Do not call this function directly - use
350     * asccalloc() instead.
351 aw0a 1 */
352    
353 jds 59 #ifdef MALLOC_DEBUG
354     # define ascmalloc(size) \
355     ascmallocf(AT_LEAST_1(size), __FILE__, __LINE__)
356     #else
357     # define ascmalloc(size) malloc(AT_LEAST_1(size))
358     #endif
359     /**<
360     * ASCEND malloc() function.
361     * If MALLOC_DEBUG is defined, the allocation is tracked.
362     * If not, then the standard system malloc() is used.
363     *
364     * @see ascmallocf()
365     * @param size size_t, size of each element.
366     * @return A (void *) to the newly-allocated block, or NULL on error.
367     */
368 aw0a 1
369 johnpye 600 ASC_DLLSPEC(VOIDPTR) ascmallocf(size_t size, CONST char * file, int line);
370 jds 59 /**<
371     * Implementation function for ascmalloc() when MALLOC_DEBUG
372     * is defined. Do not call this function directly - define
373     * MALLOC_DEBUG and use ascmalloc() instead.
374     */
375 aw0a 1
376 jds 59 #ifdef MALLOC_DEBUG
377     # define ascrealloc(ptr, size) \
378     ascreallocf((ptr), AT_LEAST_1(size), __FILE__, __LINE__)
379 aw0a 1 #else
380 jds 59 # if (defined(sun) && !defined(__SVR4))
381     # define ascrealloc(ptr,size) \
382     ((ptr)!=NULL ? realloc((ptr), AT_LEAST_1(size)) : malloc(AT_LEAST_1(size)))
383     # else
384     # define ascrealloc(ptr,size) realloc((ptr), AT_LEAST_1(size))
385     # endif
386 aw0a 1 #endif
387 jds 59 /**<
388     * ASCEND realloc() function.
389     * If MALLOC_DEBUG is defined, the allocation is tracked.
390     * If not, then the standard system realloc() is used.
391     *
392     * @see ascreallocf(), ascreallocPURE()
393     * @param ptr Pointer to memory block to reallocate.
394     * @param size size_t, size of each element.
395     * @return A (void *) to the newly-allocated block, or NULL on error.
396     */
397 aw0a 1
398 johnpye 600 ASC_DLLSPEC(VOIDPTR) ascreallocf(VOIDPTR ptr, size_t size,
399 jds 59 CONST char *file, int line);
400     /**<
401     * Implementation function for ascrealloc() when MALLOC_DEBUG
402     * is defined. Do not call this function directly - define
403     * MALLOC_DEBUG and use ascrealloc() instead.
404     */
405 aw0a 1
406 jds 59 #ifdef MALLOC_DEBUG
407     # define ascfree(ptr) ascfreef((ptr), __FILE__, __LINE__)
408     #else
409     # define ascfree(ptr) free(ptr)
410 aw0a 1 #endif
411 jds 59 /**<
412     * ASCEND free() function.
413     * If MALLOC_DEBUG is defined, the deallocation is tracked.
414     * If not, then the standard system free() is used.
415     *
416     * @see ascfreef()
417     * @param ptr Pointer to the memory block to free.
418     */
419 aw0a 1
420 johnpye 600 ASC_DLLSPEC(void) ascfreef(VOIDPTR ptr, CONST char *file, int line);
421 jds 59 /**<
422     * Implementation function for ascfree() when MALLOC_DEBUG
423     * is defined. Do not call this function directly - define
424     * MALLOC_DEBUG and use ascfree() instead.
425     */
426 aw0a 1
427 jds 59 #ifdef MALLOC_DEBUG
428     # define ascbcopy(src,dest,size) \
429     ascbcopyf((src), (dest), (size), __FILE__, __LINE__)
430     #else
431     # define ascbcopy(src,dest,size) \
432     memcpy((void *)(dest), (void *)(src), (size))
433     #endif
434     /**<
435     * ASCEND bcopy() function.
436     * Copies size bytes from src to dest. If MALLOC_DEBUG is
437     * defined, this uses custom function ascbcopyf(). If not,
438     * then memcpy() is used.
439     *
440     * @see asc_memcpy(), ascbcopyf(), ascbzero(), ascbfill()
441     * @param src Pointer to memory block to copy.
442     * @param dest Pointer to memory block to receive copy.
443     * @param size size_t, number of bytes to copy.
444     * @return A (void *) to dest.
445     */
446 aw0a 1
447 johnpye 600 ASC_DLLSPEC(VOIDPTR) ascbcopyf(CONST VOIDPTR src, VOIDPTR dest, size_t size,
448 jds 59 CONST char *file, int line);
449     /**<
450     * Implementation function for ascbcopy() when MALLOC_DEBUG
451     * is defined. Do not call this function directly - define
452     * MALLOC_DEBUG and use ascbcopy() instead.
453     */
454 aw0a 1
455 jds 59 #ifdef MALLOC_DEBUG
456     # define ascbzero(dest,length) \
457     ascbzerof((dest), (length), __FILE__, __LINE__)
458     #else
459     # define ascbzero(dest,length) memset((char *)(dest), 0, (length))
460     #endif
461     /**<
462     * ASCEND bzero() function.
463     * Sets length bytes of memory at dest to zero. If MALLOC_DEBUG
464     * is defined, this uses custom function ascbzerof(). If not,
465     * then memset() is used.
466     *
467     * @see ascbzerof(), ascbcopy(), ascbfill()
468     * @param dest Pointer to memory block to be cleared.
469     * @param length size_t, number of bytes to set to zero.
470     * @return A (void *) to dest.
471     */
472 aw0a 1
473 johnpye 600 ASC_DLLSPEC(VOIDPTR) ascbzerof(VOIDPTR dest, size_t length, CONST char *file, int line);
474 jds 54 /**<
475 jds 59 * Implementation function for ascbzero() when MALLOC_DEBUG
476     * is defined. Do not call this function directly - define
477     * MALLOC_DEBUG and use ascbzero() instead.
478     */
479    
480     #ifdef MALLOC_DEBUG
481     # define AllocatedMemory(ptr,size) AllocatedMemoryF((ptr), (size))
482     #else
483     # define AllocatedMemory(ptr,size) (1)
484     #endif
485     /**<
486 jds 54 * Evaluate a memory block for allocation status.
487 jds 59 * Return values if MALLOC is defined:
488     * - 0 no memory in the block is currently allocated
489 jds 54 * - 1 the memory block is wholly contained in an allocated block
490 jds 103 * - 2 the memory block equals an element of the memory list
491 jds 54 * - -1 the memory block is partially contained in an allocated block
492 jds 59 * If MALLOC_DEBUG is not defined, always returns 1.
493     *
494     * @param ptr Pointer to memory block to look up
495     * @param size size_t, size of the memory block to look up.
496 aw0a 1 */
497    
498 johnpye 600 ASC_DLLSPEC(int) AllocatedMemoryF(CONST VOIDPTR ptr, size_t size);
499 jds 54 /**<
500 jds 59 * Implementation function for AllocatedMemory() when
501     * MALLOC_DEBUG is defined. Do not call this function
502     * directly - define MALLOC_DEBUG and use
503     * AllocatedMemory() instead.
504 aw0a 1 */
505    
506 jds 59 #ifdef MALLOC_DEBUG
507     # define InMemoryBlock(ptr1,ptr2) InMemoryBlockF((ptr1), (ptr2))
508     #else
509     #define InMemoryBlock(ptr1,ptr2) (1)
510     #endif
511     /**<
512     * Query whether one memory block is contained within another.
513     * Returns non-zero if ptr2 is in the memory block starting at
514     * address ptr1; otherwise returns 0. If MALLOC_DEBUG is not
515     * defined, always returns 1.
516     */
517 aw0a 1
518 johnpye 600 ASC_DLLSPEC(int) InMemoryBlockF(CONST VOIDPTR ptr1, CONST VOIDPTR ptr2);
519 jds 59 /**<
520     * Implementation function for InMemoryBlock() when MALLOC_DEBUG
521     * is defined. Do not call this function directly - define
522     * MALLOC_DEBUG and use InMemoryBlock() instead.
523     */
524 aw0a 1
525 jds 59 #define ascbfill(dest,length) memset((char *)(dest), 255, (length))
526     /**<
527     * Sets length bytes of memory at dest to 255. There is
528     * no difference in implementation whether MALLOC_DEBUG is
529     * defined or not.
530     *
531     * @see ascbcopy(), ascbzero()
532     * @param dest Pointer to memory block to be set.
533     * @param length size_t, number of bytes to set to 255.
534     * @return A (void *) to dest.
535     */
536 aw0a 1
537 jds 59 #if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS)
538     # define AssertAllocatedMemory(ptr,size) \
539     asc_assert(AllocatedMemoryF((VOIDPTR)(ptr), (size_t)(AT_LEAST_1(size)))==2)
540     #else
541     # define AssertAllocatedMemory(ptr,size)
542     #endif
543     /**<
544     * Assertion that a memory block is allocated with specified size.
545     * This assertion is only active if both MALLOC_DEBUG
546     * and ALLOCATED_TESTS are defined.
547     *
548     * @param ptr Pointer to memory block to evaluate.
549     * @param size size_t, size of memory block to evaluate.
550     */
551 aw0a 1
552 jds 59 #if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS)
553     # define AssertMemory(ptr) \
554     asc_assert(AllocatedMemoryF((VOIDPTR)(ptr), 0))
555     #else
556     # define AssertMemory(ptr)
557     #endif
558     /**<
559 johnpye 599 * Assertion that ptr points to (or into) an allocated memory
560 jds 59 * block. This assertion is only active if both MALLOC_DEBUG
561     * and ALLOCATED_TESTS are defined.
562     *
563     * @param ptr Pointer to memory block to evaluate.
564     */
565 aw0a 1
566 jds 59 #if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS)
567     # define AssertContainedMemory(ptr,size) \
568     asc_assert(AllocatedMemoryF((VOIDPTR)(ptr),(size_t)(size))>0)
569     #else
570     # define AssertContainedMemory(ptr,size)
571     #endif
572     /**<
573     * Assertion that a memory block is wholly or partially
574     * contained in an allocated block.
575     * This assertion is only active if both MALLOC_DEBUG
576     * and ALLOCATED_TESTS are defined.
577     *
578     * @param ptr Pointer to memory block to evaluate.
579     * @param size size_t, size of memory block to evaluate.
580     */
581 aw0a 1
582 jds 59 #if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS)
583     # define AssertContainedIn(ptr1,ptr2) \
584     asc_assert(InMemoryBlockF((VOIDPTR)(ptr1),(VOIDPTR)(ptr2)))
585     #else
586     # define AssertContainedIn(ptr,ptr2)
587     #endif
588     /**<
589     * Assertion that memory block ptr2 is contained in the block
590     * starting at ptr1. This assertion is only active if both
591     * MALLOC_DEBUG and ALLOCATED_TESTS are defined.
592     */
593 aw0a 1
594 johnpye 67 #endif /* ASC_ASCMALLOC_H */
595 aw0a 1

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22