Re: Zero termination

From: Venugopalan G (
Date: Sun Jun 28 2009 - 01:27:25 CDT

  • Next message: Andrew Lipscomb: "Re: Zero termination"

    Hi Mike,

    The length is already part of my string class, but only for certain utility
    functions i don't want to use it because they are parsers that anyway have
    to go thru the string contents. Also its like one function parses till
    particular point and calls another function that continues parsing from
    there, so all these func calls do not require len param if i use null
    terminator. Kind of substring parsing algos.


    On Sun, Jun 28, 2009 at 1:46 AM, Michael D'Errico <>wrote:

    > Phew!.... am gonna use NULL terminator... XD
    > Even if you never encounter U+0000 (NULL) in your text
    > processing, using a NULL terminator for a string is
    > horribly inefficient. It is much, much better to keep
    > track of string length in a separate field. Consider
    > the common operation of concatenating two strings. If
    > you use NULL terminators, you need to scan the first
    > string for the NULL terminator, keeping track of the
    > length as you go, then repeat the process for the 2nd
    > string, allocate enough memory to hold the combined
    > length, and finally copy the memory. If you had the
    > lengths available, you could skip the scanning of both
    > strings and simply add the two numbers to determine
    > how much memory to allocate.
    > Of course you can do what you want, but if you look
    > around at all the modern object-oriented languages,
    > they do not use a NULL terminator for their strings;
    > they keep a character count in each string object.
    > Mike

    This archive was generated by hypermail 2.1.5 : Sun Jun 28 2009 - 01:33:30 CDT