Re: Null-terminated strings: the final analysis.



Mark McIntyre <markmcintyre@xxxxxxxxxxxxxxxxxxx> writes:

Some of the above may be true - C++ and Java use a form of
byte-counted string. However note that C's model is likely to be the
most space-efficient for non-trivial sized string, as the storage need
be only one byte longer than the string, whereas byte-counted strings
must be at least one byte longer.

Of course, the relative overhead for large counted strings is
negligible, since the overhead is constant and the string is large.
What may be of more concern is the overhead for short strings, since
implementations typically use the same sized length field for all
strings. But even then the difference is unlikely to be particularly
significant in practice.

And none of this addresses the major defect of null-terminated strings,
which is that they can't represent strings containing a zero byte.

-- [mdw]
.



Relevant Pages

  • Re: Null-terminated strings: the final analysis.
    ... Mark Wooding wrote: ... byte-counted string. ... most space-efficient for non-trivial sized string, ... the relative overhead for large counted strings is ...
    (comp.lang.c)
  • Re: Internal Representation of Strings
    ... strings are likely to be very small, ... It just seems like low overhead strings always have a ... (No, I haven't built a compiler, yet). ... saving 1 or 2 bytes will not matter so much if the memory comes ...
    (comp.compilers)
  • Re: Boost process and C
    ... thousand small strings can make a big difference in RAM used, ... portion of the memory footprint and saving the memory that avoiding the ... flags would be of real use. ... of magnitude smaller and so could easily fit in with the extra overhead. ...
    (comp.lang.c)
  • Re: Boost process and C
    ... thousand small strings can make a big difference in RAM used, ... portion of the memory footprint and saving the memory that avoiding the ... flags would be of real use. ... the subset of it that is likely to be actually in use is probably an order of magnitude smaller and so could easily fit in with the extra overhead. ...
    (comp.lang.c)
  • Re: How much lossless compression is possible in images?
    ... In theory a compression algorithm just performs a simple substitution. ... all possible strings. ... well, that is, one that adds no overhead. ...
    (sci.math)