Skip to content

Instantly share code, notes, and snippets.

@jcupitt
Last active June 20, 2016 11:30
Show Gist options
  • Save jcupitt/2ed57a96c0cb2faa91615d9ebb8325a4 to your computer and use it in GitHub Desktop.
Save jcupitt/2ed57a96c0cb2faa91615d9ebb8325a4 to your computer and use it in GitHub Desktop.
test vips memory behaviour
/* compile with
*
* g++ -g -Wall danila.cpp `pkg-config vips --cflags --libs`
*/
#include <vector>
#include <string>
#include <iostream>
#include <vips/vips.h>
int
main( int argc, char **argv )
{
if( VIPS_INIT( argv[0] ) )
vips_error_exit( NULL );
vips_cache_set_max( 0 );
std::vector<VipsImage *> aImages;
for( int i = 0; i < argc - 1; i++ ) {
VipsImage *image;
VipsRegion *region;
if( !(image = vips_image_new_from_file( argv[i + 1], NULL)) )
vips_error_exit( NULL );
aImages.push_back( image );
VipsRect rect = { 0, 0, image->Xsize / 3, image->Ysize / 3 };
region = vips_region_new( image );
if( vips_region_prepare( region, &rect ) )
vips_error_exit( NULL );
g_object_unref( region );
}
std::cout << "Before image unref, ";
std::cout << vips_tracked_get_allocs() << " allocations, ";
std::cout << vips_tracked_get_mem() << " bytes, ";
std::cout << vips_tracked_get_files() << " open files" << std::endl;
// Here we check memory consumption
std::cout << "Paused, type something and press return ..." << std::endl;
std::string a;
std::cin >> a;
for( unsigned int i = 0; i < aImages.size(); i++ )
g_object_unref( aImages[i] );
std::cout << "Live objects:" << std::endl;
vips_object_print_all();
std::cout << "After image unref, ";
std::cout << vips_tracked_get_allocs() << " allocations, ";
std::cout << vips_tracked_get_mem() << " bytes, ";
std::cout << vips_tracked_get_files() << " open files" << std::endl;
// Here we check memory consumption
std::cout << "Paused, type something and press return ..." << std::endl;
std::cin >> a;
std::cout << "Exiting ..." << std::endl;
return( 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment