Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!doctor.chem.yale.edu From: jim@doctor.chem.yale.edu (James F. Blake) Newsgroups: comp.lang.c Subject: Memory allocation / data access Message-ID: <29491@cs.yale.edu> Date: 15 Mar 91 16:42:53 GMT Sender: news@cs.yale.edu Distribution: na Organization: Laboratory for Computational Chemistry, Yale University Lines: 38 Nntp-Posting-Host: rassilon.chem.yale.edu I have two questions: 1) Have I allocated the storage properly and 2) Is this the most efficient way to access the data (i.e., monomer[].atom[].x). I am allocating storage for n-molecules, each with n-atoms and 3 coordinates. Any information would be greatly appreciated. Jim typedef struct { double x; double y; double z; } cartesian; typedef struct { cartesian *atom; } solvent; solvent *monomer; /* Allocate the necessary storage */ if ((monomer = (solvent *) malloc (nmol * sizeof (solvent *)))==NULL) exit(1); for (i = 0; i < nmol; i++) if ((monomer[i].atom = (cartesian *) calloc (natoms,sizeof(cartesian)))==NULL) exit(1); /* check components */ for (k = 0; k < natoms; k++) { for (l = 0; l < natoms; l++) { xdis = fabs (monomer[i].atom[k].x - monomer[j].atom[l].x); ydis = fabs (monomer[i].atom[k].y - monomer[j].atom[l].y); zdis = fabs (monomer[i].atom[k].z - monomer[j].atom[l].z); } }