1 /* memory utilities
2  *
3  * J.Cupitt, 8/4/93
4  */
5 
6 /*
7 
8     This file is part of VIPS.
9 
10     VIPS is free software; you can redistribute it and/or modify
11     it under the terms of the GNU Lesser General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14 
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU Lesser General Public License for more details.
19 
20     You should have received a copy of the GNU Lesser General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23     02110-1301  USA
24 
25  */
26 
27 /*
28 
29     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
30 
31  */
32 
33 #ifndef VIPS_MEMORY_H
34 #define VIPS_MEMORY_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /*__cplusplus*/
39 
40 #define VIPS_FREEF( F, S ) G_STMT_START { \
41         if( S ) { \
42                 (void) F( (S) ); \
43                 (S) = 0; \
44         } \
45 } G_STMT_END
46 
47 #define VIPS_FREE( S ) VIPS_FREEF( g_free, (S) );
48 
49 #define VIPS_SETSTR( S, V ) \
50 G_STMT_START { \
51         const char *sst = (V); \
52 	\
53         if( (S) != sst ) { \
54                 if( !(S) || !sst || strcmp( (S), sst ) != 0 ) { \
55                         VIPS_FREE( S ); \
56                         if( sst ) \
57                                 (S) = g_strdup( sst ); \
58                 } \
59         } \
60 } G_STMT_END
61 
62 #define VIPS_NEW( OBJ, T ) \
63 	((T *) vips_malloc( VIPS_OBJECT( OBJ ), sizeof( T )))
64 #define VIPS_ARRAY( OBJ, N, T ) \
65 	((T *) vips_malloc( VIPS_OBJECT( OBJ ), (N) * sizeof( T )))
66 
67 void *vips_malloc( VipsObject *object, size_t size );
68 char *vips_strdup( VipsObject *object, const char *str );
69 
70 void vips_tracked_free( void *s );
71 void *vips_tracked_malloc( size_t size );
72 size_t vips_tracked_get_mem( void );
73 size_t vips_tracked_get_mem_highwater( void );
74 int vips_tracked_get_allocs( void );
75 
76 int vips_tracked_open( const char *pathname, int flags, int mode );
77 int vips_tracked_close( int fd );
78 int vips_tracked_get_files( void );
79 
80 #ifdef __cplusplus
81 }
82 #endif /*__cplusplus*/
83 
84 #endif /*IM_MEMORY_H*/
85