1 /* 2 3 -Abstract 4 5 The memory allocation prototypes and macros for use in CSPICE. 6 7 -Disclaimer 8 9 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 10 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 11 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 12 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 13 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 14 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 15 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 16 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 17 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 18 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 19 20 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 21 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 22 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 23 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 24 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 25 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 26 27 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 28 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 29 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 30 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 31 32 -Particulars 33 34 The routines maintain a count of the number of mallocs vs. free, 35 signalling an error if any unreleased memory exists at the end 36 of an Icy interface call. 37 38 The macro ALLOC_CHECK performs malloc/free test. If used, the macro 39 should exists at the end of any routine using these memory management 40 routines. 41 42 Prototypes in this file: 43 44 alloc_SpiceBoolean_C_array 45 alloc_SpiceDouble_C_array 46 alloc_SpiceInt_C_array 47 alloc_SpiceMemory 48 alloc_SpiceString 49 alloc_SpiceString_C_Copy_array 50 alloc_SpiceString_C_array 51 alloc_SpiceString_Pointer_array 52 alloc_count 53 free_SpiceMemory 54 free_SpiceString_C_array 55 zzalloc_count 56 57 -Version 58 59 CSPICE 1.3.0 26-AUG-2016 (EDW) 60 61 Added routine alloc_SpiceBoolean_C_array. 62 63 CSPICE 1.0.3 02-MAY-2008 (EDW) 64 65 Added alloc_count prototype. 66 67 CSPICE 1.0.2 10-MAY-2007 (EDW) 68 69 Minor edits to clarify 'size' in alloc_SpiceMemory as 70 size_t. 71 72 CSPICE 1.0.1 23-JUN-2005 (EDW) 73 74 Add prototype for alloc_SpiceString_Pointer_array, allocate 75 an array of pointers to SpiceChar. 76 77 Icy 1.0.0 December 19, 2003 (EDW) 78 79 Initial release. 80 81 */ 82 83 #ifndef ZZALLOC_H 84 #define ZZALLOC_H 85 86 /* 87 Allocation call prototypes: 88 */ 89 int alloc_count (); 90 91 SpiceChar ** alloc_SpiceString_C_array ( int string_length, 92 int string_count ); 93 94 SpiceChar ** alloc_SpiceString_C_Copy_array ( int array_len , 95 int string_len, 96 SpiceChar ** array ); 97 98 SpiceDouble * alloc_SpiceDouble_C_array ( int rows, 99 int cols ); 100 101 SpiceInt * alloc_SpiceInt_C_array ( int rows, 102 int cols ); 103 104 SpiceBoolean * alloc_SpiceBoolean_C_array ( int rows, 105 int cols ); 106 107 SpiceChar * alloc_SpiceString ( int length ); 108 109 SpiceChar ** alloc_SpiceString_Pointer_array( int array_len ); 110 111 void free_SpiceString_C_array ( int dim, 112 SpiceChar ** array ); 113 114 void * alloc_SpiceMemory ( size_t size ); 115 116 void free_SpiceMemory ( void * ptr ); 117 118 119 /* 120 Simple macro to ensure a zero value alloc count at end of routine. 121 Note, the need to use this macro exists only in those routines 122 allocating/deallocating memory. 123 */ 124 #define ALLOC_CHECK if ( alloc_count() != 0 ) \ 125 { \ 126 setmsg_c ( "Malloc/Free count not zero at end of routine." \ 127 " Malloc count = #."); \ 128 errint_c ( "#", alloc_count() ); \ 129 sigerr_c ( "SPICE(MALLOCCOUNT)" ); \ 130 } 131 132 #endif 133 134