Top |
Functions
#define | VIPS_FREEF() |
#define | VIPS_FREE() |
#define | VIPS_SETSTR() |
#define | VIPS_NEW() |
#define | VIPS_ARRAY() |
void * | vips_malloc () |
char * | vips_strdup () |
int | vips_free () |
void | vips_tracked_free () |
void * | vips_tracked_malloc () |
size_t | vips_tracked_get_mem () |
size_t | vips_tracked_get_mem_highwater () |
int | vips_tracked_get_allocs () |
int | vips_tracked_open () |
int | vips_tracked_close () |
int | vips_tracked_get_files () |
Description
These functions cover two main areas.
First, some simple utility functions over the underlying
g_malloc()
/g_free()
functions. Memory allocated and freeded using these
functions is interchangeable with any other glib library.
Second, a pair of functions, vips_tracked_malloc()
and vips_tracked_free()
,
which are NOT compatible. If you g_free()
memory that has been allocated
with vips_tracked_malloc()
you will see crashes.
The tracked functions are only suitable for large allocations internal to the library, for example pixel buffers. libvips watches the total amount of live tracked memory and uses this information to decide when to trim caches.
Functions
VIPS_NEW()
#define VIPS_NEW( OBJ, T )
Allocate memory for a thing of type T
. The memory is not
cleared.
This macro cannot fail. See vips_tracked_malloc()
if you are
allocating large amounts of memory.
See also: vips_malloc()
.
VIPS_ARRAY()
#define VIPS_ARRAY( OBJ, N, T )
Allocate memory for an array of objects of type T
. The memory is not
cleared.
This macro cannot fail. See vips_tracked_malloc()
if you are
allocating large amounts of memory.
See also: vips_malloc()
.
Parameters
OBJ |
allocate memory local to |
|
N |
number of |
|
T |
type of thing to allocate |
vips_malloc ()
void * vips_malloc (VipsObject *object
,size_t size
);
g_malloc() local to object
, that is, the memory will be automatically
freed for you when the object is closed. If object
is NULL
, you need to
free the memory explicitly with g_free()
.
This function cannot fail. See vips_tracked_malloc()
if you are
allocating large amounts of memory.
See also: vips_tracked_malloc()
.
Parameters
object |
allocate memory local to this VipsObject, or |
[nullable] |
size |
number of bytes to allocate |
vips_strdup ()
char * vips_strdup (VipsObject *object
,const char *str
);
g_strdup() a string. When object
is freed, the string will be freed for
you. If object
is NULL
, you need to
free the memory yourself with g_free()
.
This function cannot fail.
See also: vips_malloc()
.
vips_free ()
int
vips_free (void *buf
);
Frees memory with g_free()
and returns 0. Handy for callbacks.
See also: vips_malloc()
.
vips_tracked_free ()
void
vips_tracked_free (void *s
);
Only use it to free
memory that was previously allocated with vips_tracked_malloc()
with a
NULL
first argument.
See also: vips_tracked_malloc()
.
vips_tracked_malloc ()
void *
vips_tracked_malloc (size_t size
);
Allocate an area of memory that will be tracked by vips_tracked_get_mem()
and friends.
If allocation fails, vips_malloc()
returns NULL
and
sets an error message.
You must only free the memory returned with vips_tracked_free()
.
See also: vips_tracked_free()
, vips_malloc()
.
vips_tracked_get_mem ()
size_t
vips_tracked_get_mem (void
);
Returns the number of bytes currently allocated via vips_malloc()
and
friends. vips uses this figure to decide when to start dropping cache, see
VipsOperation.
vips_tracked_get_mem_highwater ()
size_t
vips_tracked_get_mem_highwater (void
);
Returns the largest number of bytes simultaneously allocated via
vips_tracked_malloc()
. Handy for estimating max memory requirements for a
program.
vips_tracked_get_allocs ()
int
vips_tracked_get_allocs (void
);
Returns the number of active allocations.
vips_tracked_open ()
int vips_tracked_open (const char *pathname
,int flags
,...
);
Exactly as open(2), but the number of files current open via
vips_tracked_open()
is available via vips_tracked_get_files()
. This is used
by the vips operation cache to drop cache when the number of files
available is low.
You must only close the file descriptor with vips_tracked_close()
.
See also: vips_tracked_close()
, vips_tracked_get_files()
.
vips_tracked_close ()
int
vips_tracked_close (int fd
);
Exactly as close(2), but update the number of files currently open via
vips_tracked_get_files()
. This is used
by the vips operation cache to drop cache when the number of files
available is low.
You must only close file descriptors opened with vips_tracked_open()
.
See also: vips_tracked_open()
, vips_tracked_get_files()
.