Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Patch for curses module



On Sep 13,  1:58pm, Sebastian Gniazdowski wrote:
}
} _provide_clean_memory_to_old_zsh() {
}     local i=100
}     while (( i-- )); do
}         local a b
}         a="               "
}         b="               "
}         unset a b
}     done
} }

If malloc works the way you think, that loop is just going to allocate
and free the same two blocks over and over.  Declaring "local" inside a
loop doesn't have any special meaning.  You would at least need e.g.

  while (( i-- )); do
    local a$i="                 " b$i="                 "
  done

Then because declared local, all the a$i and b$i will be freed at the end
of the function scope, you don't need an explicit unset.

} Hash node which is part of colorpairnode as:
} struct hashnode {
}     HashNode next;          /* next in hash chain */
}     char *nam;                  /* hash key           */
}     int flags;                      /* various flags      */
} };

Yes, but you need to clear single blocks the size of the entire
colorpairnode struct (18+ bytes, a hashnode plus a short) rather
than just the size of the prefix hashnode.

} Therefore filling a 16/32 byte area with zeros or e.g. spaces and then
} freeing it should provide proper memory for zcurses. But this doesn't
} happen. Does unset free memory? What can be done to allocate and free
} 16/32 bytes block?

Even if you get the size right, the malloc library isn't guaranteed to
re-use freed memory in LIFO order.  It may (re)use it in the order
that it can access it the fastest, whether or not that's best-fit.
It might also aggressively release freed blocks back to the OS, in
which case any value you write there may be clobbered by another
thread even if you do get back the same block you previously freed.

You can try to thwart this by allocating something that is NOT freed
every so often, so that there's less chance of a contiguous block for
malloc to release, but ultimately trying to control memory layout
from the shell script level is never going to produce a consistent
result.



Messages sorted by: Reverse Date, Date, Thread, Author