| VIPS Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <vips/vips.h> #define IM_NEW ( IM, T ) #define IM_ARRAY ( IM, N, T ) void * im_malloc (VipsImage *im, size_t sz); int im_free (void *);
Simple memory allocation utilities. These functions and macros help
allocate and free memory. Most of VIPS uses them, though some parts use
the g_malloc() system instead, confusingly.
If you compile with DEBUGM it will track allocations for you, though
valgrind or dmalloc are better solutions.
#define IM_NEW( IM, T ) ((T *) im_malloc( (IM), sizeof( T )))
|
allocate memory local to IM, or NULL for no auto-free
|
|
type of thing to allocate |
Returns : |
A pointer of type T *, or NULL on error.
|
#define IM_ARRAY( IM, N, T ) ((T *) im_malloc( (IM), (N) * sizeof( T )))
|
allocate memory local to IM, or NULL for no auto-free
|
|
number of T 's to allocate
|
|
type of thing to allocate |
Returns : |
A pointer of type T *, or NULL on error.
|
void * im_malloc (VipsImage *im, size_t sz);
Malloc local to im, that is, the memory will be automatically
freed for you when the image is closed. If im is NULL, you need to free
the memory explicitly with im_free().
If allocation fails im_malloc() returns NULL and
sets an error message.
If two threads try to allocate local to the same im at the same time, you
can get heap corruption.
|
allocate memory local to this IMAGE, or NULL
|
|
number of bytes to allocate |
Returns : |
a pointer to the allocated memory, or NULL on error.
|
int im_free (void *);
VIPS free function. VIPS tries to use this instead of free(). It always
returns zero, so it can be used as a callback handler.
Only use it to free
memory that was previously allocated with im_malloc() with a NULL first
argument.
|
memory to free |
Returns : |
0 |