Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT Well, you're leaking memory left and right, but not quite in the way I was thinking. Fixed sequence below:</p> <p>Specifically, when you do:</p> <pre><code>atoms = (struct Atom *) malloc(sizeof(struct Atom) * numAtoms); // 1 atoms = (*amino).atoms; // 2 // ... atoms = (struct Atom *) malloc(sizeof(struct Atom)); // 3 free(atoms); // 4 </code></pre> <p>What is happening is that you are allocating some memory and putting the address in <code>atoms</code> in step(1). Then, you toss away that address and instead point <code>atoms</code> at part of the inside of your <code>amino</code> structure in (2). Then you allocate a <em>second</em> pointer with a single atom. Finally, you call <code>free</code> on that. You treat <code>bonds</code> the same way. You probably mean something like this:</p> <pre><code>atoms = (struct Atom *) malloc(sizeof(struct Atom) * numAtoms); // 1 memcpy(atoms, (*amino).atoms, sizeof(struct Atom) * numAtoms); // 2 // ... // delete 3 free(atoms); // 4 </code></pre> <p>Note that if an Atom has any pointer components you might want to do a <code>for</code> loop and copy the atoms individually along with their contents, which you would then have to individually <code>free</code> at the return point.</p> <p>...or maybe just this if you are only wanting to read the atoms data from the structure:</p> <pre><code>atoms = (*amino).atoms; // delete 1, 3, 4 entirely and just read directly from the structure </code></pre> <p>Other answers talking about the amount of space in <code>diff</code> and other issues are probably also worth investigating.</p> <p>EDIT: fixed the sequence of calls to match the code sample.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload