Hello,
I'm using the following code to convert molfiles to PNG with Openbabel-2.3.2 on
Ubuntu 14.04 LTS:
typedef struct
{
size_t datasz;
char data[1];
} _PNG;
extern "C" _PNG *
ob_molfile_to_png (char *molfile, int w, int h)
{
OBMol mol;
OBConversion conv;
string tmpStr (molfile);
string outstr;
istringstream molstream (tmpStr);
ostringstream PNGstream,_w,_h;
_PNG *tmpPNG;
size_t PNG_size;
_w << w;
_h << h;
conv.SetInAndOutFormats ("MDL", "_png2");
conv.AddOption ("d", OBConversion::OUTOPTIONS);
conv.AddOption ("gen2D", OBConversion::OUTOPTIONS);
conv.AddOption ("w", OBConversion::OUTOPTIONS,_w.str().c_str());
conv.AddOption ("h", OBConversion::OUTOPTIONS,_h.str().c_str());
conv.Read (&mol, &molstream);
if (mol.Empty ())
return NULL;
conv.Write (&mol, &PNGstream);
outstr = PNGstream.str();
PNG_size = outstr.length();
tmpPNG = (_PNG*) malloc (sizeof(_PNG)+PNG_size);
tmpPNG->datasz = PNG_size;
memcpy(tmpPNG->data,outstr.c_str(),PNG_size);
return (tmpPNG);
}
This works, but for 500x500 images, it takes about 1MB of RAM per image. The
amount of memory used is bound to the requested size of the image.
Since this is running in a database context, the memory is held for all images
converted until I close the connection, which could make the Linux server run
out of memory.
I am freeing the malloc'ed memory returned from this function properly, so I
suspect that something in Openbabel or Cairo is holding memory references
longer than needed.
Please could somebody clarify on that? Is it expected behavior, a bug, or am I
plainly doing something wrong?
Best regards,
Ernst-Georg
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
OpenBabel-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel