| [2aa6644] | 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 | /******************************************************************************
|
|---|
| 14 | *
|
|---|
| 15 | * Header file for memory management utilities
|
|---|
| 16 | *
|
|---|
| 17 | *****************************************************************************/
|
|---|
| 18 |
|
|---|
| 19 | #ifndef hypre_MEMORY_HEADER
|
|---|
| 20 | #define hypre_MEMORY_HEADER
|
|---|
| 21 |
|
|---|
| 22 | #ifdef __cplusplus
|
|---|
| 23 | extern "C" {
|
|---|
| 24 | #endif
|
|---|
| 25 |
|
|---|
| 26 | /*--------------------------------------------------------------------------
|
|---|
| 27 | * Use "Debug Malloc Library", dmalloc
|
|---|
| 28 | *--------------------------------------------------------------------------*/
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HYPRE_MEMORY_DMALLOC
|
|---|
| 31 |
|
|---|
| 32 | #define hypre_InitMemoryDebug(id) hypre_InitMemoryDebugDML(id)
|
|---|
| 33 | #define hypre_FinalizeMemoryDebug() hypre_FinalizeMemoryDebugDML()
|
|---|
| 34 |
|
|---|
| 35 | #define hypre_TAlloc(type, count) \
|
|---|
| 36 | ( (type *)hypre_MAllocDML((unsigned int)(sizeof(type) * (count)),\
|
|---|
| 37 | __FILE__, __LINE__) )
|
|---|
| 38 |
|
|---|
| 39 | #define hypre_CTAlloc(type, count) \
|
|---|
| 40 | ( (type *)hypre_CAllocDML((unsigned int)(count), (unsigned int)sizeof(type),\
|
|---|
| 41 | __FILE__, __LINE__) )
|
|---|
| 42 |
|
|---|
| 43 | #define hypre_TReAlloc(ptr, type, count) \
|
|---|
| 44 | ( (type *)hypre_ReAllocDML((char *)ptr,\
|
|---|
| 45 | (unsigned int)(sizeof(type) * (count)),\
|
|---|
| 46 | __FILE__, __LINE__) )
|
|---|
| 47 |
|
|---|
| 48 | #define hypre_TFree(ptr) \
|
|---|
| 49 | ( hypre_FreeDML((char *)ptr, __FILE__, __LINE__), ptr = NULL )
|
|---|
| 50 |
|
|---|
| 51 | /*--------------------------------------------------------------------------
|
|---|
| 52 | * Use standard memory routines
|
|---|
| 53 | *--------------------------------------------------------------------------*/
|
|---|
| 54 |
|
|---|
| 55 | #else
|
|---|
| 56 |
|
|---|
| 57 | #define hypre_InitMemoryDebug(id)
|
|---|
| 58 | #define hypre_FinalizeMemoryDebug()
|
|---|
| 59 |
|
|---|
| 60 | #define hypre_TAlloc(type, count) \
|
|---|
| 61 | ( (type *)hypre_MAlloc((unsigned int)(sizeof(type) * (count))) )
|
|---|
| 62 |
|
|---|
| 63 | #define hypre_CTAlloc(type, count) \
|
|---|
| 64 | ( (type *)hypre_CAlloc((unsigned int)(count), (unsigned int)sizeof(type)) )
|
|---|
| 65 |
|
|---|
| 66 | #define hypre_TReAlloc(ptr, type, count) \
|
|---|
| 67 | ( (type *)hypre_ReAlloc((char *)ptr, (unsigned int)(sizeof(type) * (count))) )
|
|---|
| 68 |
|
|---|
| 69 | #define hypre_TFree(ptr) \
|
|---|
| 70 | ( hypre_Free((char *)ptr), ptr = NULL )
|
|---|
| 71 |
|
|---|
| 72 | #endif
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | #ifdef HYPRE_USE_PTHREADS
|
|---|
| 76 |
|
|---|
| 77 | #define hypre_SharedTAlloc(type, count) \
|
|---|
| 78 | ( (type *)hypre_SharedMAlloc((unsigned int)(sizeof(type) * (count))) )
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | #define hypre_SharedCTAlloc(type, count) \
|
|---|
| 82 | ( (type *)hypre_SharedCAlloc((unsigned int)(count),\
|
|---|
| 83 | (unsigned int)sizeof(type)) )
|
|---|
| 84 |
|
|---|
| 85 | #define hypre_SharedTReAlloc(ptr, type, count) \
|
|---|
| 86 | ( (type *)hypre_SharedReAlloc((char *)ptr,\
|
|---|
| 87 | (unsigned int)(sizeof(type) * (count))) )
|
|---|
| 88 |
|
|---|
| 89 | #define hypre_SharedTFree(ptr) \
|
|---|
| 90 | ( hypre_SharedFree((char *)ptr), ptr = NULL )
|
|---|
| 91 |
|
|---|
| 92 | #else
|
|---|
| 93 |
|
|---|
| 94 | #define hypre_SharedTAlloc(type, count) hypre_TAlloc(type, (count))
|
|---|
| 95 | #define hypre_SharedCTAlloc(type, count) hypre_CTAlloc(type, (count))
|
|---|
| 96 | #define hypre_SharedTReAlloc(type, count) hypre_TReAlloc(type, (count))
|
|---|
| 97 | #define hypre_SharedTFree(ptr) hypre_TFree(ptr)
|
|---|
| 98 |
|
|---|
| 99 | #endif
|
|---|
| 100 |
|
|---|
| 101 | /*--------------------------------------------------------------------------
|
|---|
| 102 | * Prototypes
|
|---|
| 103 | *--------------------------------------------------------------------------*/
|
|---|
| 104 |
|
|---|
| 105 | /* hypre_memory.c */
|
|---|
| 106 | int hypre_OutOfMemory( int size );
|
|---|
| 107 | char *hypre_MAlloc( int size );
|
|---|
| 108 | char *hypre_CAlloc( int count , int elt_size );
|
|---|
| 109 | char *hypre_ReAlloc( char *ptr , int size );
|
|---|
| 110 | void hypre_Free( char *ptr );
|
|---|
| 111 | char *hypre_SharedMAlloc( int size );
|
|---|
| 112 | char *hypre_SharedCAlloc( int count , int elt_size );
|
|---|
| 113 | char *hypre_SharedReAlloc( char *ptr , int size );
|
|---|
| 114 | void hypre_SharedFree( char *ptr );
|
|---|
| 115 | double *hypre_IncrementSharedDataPtr( double *ptr , int size );
|
|---|
| 116 |
|
|---|
| 117 | /* memory_dmalloc.c */
|
|---|
| 118 | int hypre_InitMemoryDebugDML( int id );
|
|---|
| 119 | int hypre_FinalizeMemoryDebugDML( void );
|
|---|
| 120 | char *hypre_MAllocDML( int size , char *file , int line );
|
|---|
| 121 | char *hypre_CAllocDML( int count , int elt_size , char *file , int line );
|
|---|
| 122 | char *hypre_ReAllocDML( char *ptr , int size , char *file , int line );
|
|---|
| 123 | void hypre_FreeDML( char *ptr , char *file , int line );
|
|---|
| 124 |
|
|---|
| 125 | #ifdef __cplusplus
|
|---|
| 126 | }
|
|---|
| 127 | #endif
|
|---|
| 128 |
|
|---|
| 129 | #endif
|
|---|