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_count 45 alloc_SpiceMemory 46 alloc_SpiceString_C_array 47 alloc_SpiceString_C_Copy_array 48 alloc_SpiceDouble_C_array 49 alloc_SpiceInt_C_array 50 alloc_SpiceString 51 alloc_SpiceString_Pointer_array 52 free_SpiceString_C_array 53 free_SpiceMemory 54 55 -Version 56 57 CSPICE 1.0.1 23-JUN-2005 (EDW) 58 59 Add prototype for alloc_SpiceString_Pointer_array, allocate 60 an array of pointers to SpiceChar. 61 62 Icy 1.0.0 December 19, 2003 (EDW) 63 64 Initial release. 65 66 */ 67 68 #ifndef ZZALLOC_H 69 #define ZZALLOC_H 70 71 /* Allocation call prototypes: */ 72 int alloc_count ( SpiceChar* op ); 73 74 SpiceChar ** alloc_SpiceString_C_array ( int string_length, 75 int string_count ); 76 77 SpiceChar ** alloc_SpiceString_C_Copy_array ( int array_len , 78 int string_len, 79 SpiceChar ** array ); 80 81 SpiceDouble * alloc_SpiceDouble_C_array ( int rows, 82 int cols ); 83 84 SpiceInt * alloc_SpiceInt_C_array ( int rows, 85 int cols ); 86 87 SpiceChar * alloc_SpiceString ( int length ); 88 89 SpiceChar ** alloc_SpiceString_Pointer_array( int array_len ); 90 91 void free_SpiceString_C_array ( int dim, 92 SpiceChar ** array ); 93 94 void * alloc_SpiceMemory ( unsigned size ); 95 96 void free_SpiceMemory ( void * ptr ); 97 98 99 /* 100 Simple macro to ensure a zero value alloc count at end of routine. 101 Note, the need to use this macro exists only in those routines 102 allocating/deallocating memory. 103 */ 104 #define ALLOC_CHECK if ( alloc_count( "=" ) != 0 ) \ 105 { \ 106 setmsg_c ( "Malloc/Free count not zero at end of routine." \ 107 " Malloc count = #."); \ 108 errint_c ( "#", alloc_count ( "=" ) ); \ 109 sigerr_c ( "SPICE(MALLOCCOUNT)" ); \ 110 } 111 112 #endif 113 114