[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [modeller_usage] Modeller API



Dear Ben,

Thanks very much for your reply, I did find the accessor methods in mod_core.h, thanks.  My goal is a very general one - being able to readily interface directly between existing code that I have (or code that I will write) in C++ and the modeller data structures, for repetitive and iterative calculations.

I encountered one pitfall that I did not find a reference to anywhere (there's a bad pun in this I'm sure), which may be implicitly obvious to C programmers but escaped my C++-string oriented brain until I'd reassured myself I wasn't botching reference counting in Python.  I was accessing the 'atom type' and 'atom element' members of the mod_coordinates struct using the "mod_coordinates_xxxx_get" methods, and passing this to a C++ string.  My humble program was consuming vast quantities of memory.  Eventually I realised that this method must be "mallocing" the char* rather than simply returning a reference to static data.  So I replaced:
string ele = mod_coordinates_atmnam_get(&mod.cd, idx)
with
char* buf = mod_coordinates_atmnam_get(&mod.cd, idx)
string ele=buf
free(buf)
and this seemed to do the trick.

Am I on the right track?  If so, it might be useful to include a comment to this effect either in the API section of the modeller manual or in the header file itself.

Thanks again!
James