Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #97998

Re: Counted strings

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: Counted strings
Date 2016-12-04 22:37 +0000
Organization A noiseless patient Spider
Message-ID <o225od$8n4$1@dont-email.me> (permalink)
References (2 earlier) <o21q7d$uoi$1@gioia.aioe.org> <o21qfp$uq6$1@dont-email.me> <o21r92$10kd$1@gioia.aioe.org> <o21sq1$7rd$1@dont-email.me> <o21ttc$15ck$1@gioia.aioe.org>

Show all headers | View raw


On 04/12/2016 20:22, Robert Spanjaard wrote:
> On 04-12-16 21:04, David Brown wrote:
>>>> Yes, but supporting three different sizes (8-bit, 16-bit and 32-bit)
>>>> makes access to all three sizes a little more complicated and less
>>>> efficient.  And an extra couple of bytes on a string in the 255 - 65535
>>>> range is a minor cost in space.  Also, you need some bits to encode the
>>>> choice of size - for 8/32, one bit is sufficient and your real sizes
>>>> are
>>>> 7-bit and 31-bit.  For 8/16/32, you need two bits and your sizes are
>>>> 6-bit, 14-bit and 30-bit.  (More complicated schemes are, of course,
>>>> perfectly possible - at the cost of more run-time in figuring out the
>>>> true length of the string.)
>>>
>>> Again, for normal text files, supporting 32 bit doesn't make sense.
>>
>> Even then, it depends on what you are doing.  If you are writing a
>> "less" or "grep" utility, then storing everything as a single big string
>> makes sense - and you'd need more than 16-bit.
>
> For single-string applications like grep or less trying to save a byte or
> two in the counting data doesn't make much sense. :)

I don't know that the OP had it mind for counted strings; whether as a 
library idea or to be added to the language.

But suppose you had a layout like this:

  struct {
      char barcode[16];
      char descr[32]
      char categorycode[6];
      char suppliercode[4];
      char info [14];
      char tariff[12];
  } ...

If you wanted counted strings for these fields, you don't really want a 
32- or 64-bit count as part of the space available for the string 
(especially for those 6- and 4-char fields!).

Even the zero terminator is unwelcome, as it means, if you need a string 
that can be up to 4 characters long, that you need to set aside 5 bytes. 
That can upset the alignment of neighbouring numeric fields and lead to 
padding bytes, wasting even more space.

(The way I do this in some apps makes available all the characters in 
the field with a couple of techniques, one of which uses a count.)

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Counted strings jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-03 23:58 +0100
  Re: Counted strings supercat@casperkitty.com - 2016-12-03 15:40 -0800
  Counted stringsl Thiago Adams <thiago.adams@gmail.com> - 2016-12-03 15:40 -0800
  Re: Counted strings BartC <bc@freeuk.com> - 2016-12-04 00:20 +0000
  Re: Counted strings Richard Damon <Richard@Damon-Family.org> - 2016-12-03 21:26 -0500
    Re: Counted strings jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-04 18:11 +0100
    Re: Counted strings Mark Storkamp <mstorkamp@yahoo.com> - 2016-12-04 19:25 -0600
  Re: Counted strings Keith Thompson <kst-u@mib.org> - 2016-12-03 18:57 -0800
  Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-04 16:33 +0100
    Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-04 07:52 -0800
      Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-04 17:10 +0100
        Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-04 10:14 -0800
          Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-04 20:20 +0100
            Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-04 16:49 -0800
              Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-05 10:40 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 05:51 -0800
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-05 16:10 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 07:38 -0800
                Re: Counted strings Melzzzzz <mel@zzzzz.com> - 2016-12-05 16:56 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 08:04 -0800
                Re: Counted strings Melzzzzz <mel@zzzzz.com> - 2016-12-05 17:16 +0100
                Re: Counted strings Jerry Stuckle <jstucklex@attglobal.net> - 2016-12-05 16:12 -0500
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 13:24 -0800
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-06 10:53 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 03:52 -0800
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-06 13:32 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 04:48 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 13:42 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 05:16 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 14:39 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 05:24 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 05:41 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 05:47 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 14:48 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 05:54 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 06:21 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 06:24 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 18:06 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 10:19 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 19:45 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 11:10 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 12:58 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 14:08 -0800
                Re: Counted strings Keith Thompson <kst-u@mib.org> - 2016-12-06 11:25 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 05:28 -0800
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-06 16:21 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 07:29 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 07:39 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 08:32 -0800
                Re: Counted strings fir <profesor.fir@gmail.com> - 2016-12-06 08:32 -0800
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 16:28 +0000
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 08:34 -0800
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 18:27 +0000
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 10:36 -0800
                Re: Counted strings Ian Collins <ian-news@hotmail.com> - 2016-12-06 08:19 +1300
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 11:22 -0800
                Re: Counted strings Ian Collins <ian-news@hotmail.com> - 2016-12-06 08:26 +1300
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 19:36 +0000
                Re: Counted strings Ian Collins <ian-news@hotmail.com> - 2016-12-06 08:41 +1300
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 11:48 -0800
                Re: Counted strings Thiago Adams <thiago.adams@gmail.com> - 2016-12-05 11:59 -0800
                Re: Counted strings jameskuyper@verizon.net - 2016-12-05 12:12 -0800
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 12:18 -0800
                Re: Counted strings jameskuyper@verizon.net - 2016-12-05 13:17 -0800
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 13:29 -0800
                Re: Counted strings jameskuyper@verizon.net - 2016-12-05 15:37 -0800
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 15:43 -0800
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-06 13:40 +0100
                Re: Counted strings "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-06 12:00 -0500
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 10:09 -0800
                Re: Counted strings Jerry Stuckle <jstucklex@attglobal.net> - 2016-12-06 13:33 -0500
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-06 21:24 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-06 12:56 -0800
                Re: Counted strings Keith Thompson <kst-u@mib.org> - 2016-12-05 12:22 -0800
                Re: Counted strings supercat@casperkitty.com - 2016-12-05 08:36 -0800
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 17:31 +0000
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-05 22:07 +0100
                Re: Counted strings Ian Collins <ian-news@hotmail.com> - 2016-12-06 10:14 +1300
                Re: Counted strings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-05 22:11 +0000
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-06 02:13 +0000
                Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-05 21:57 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 13:01 -0800
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 21:22 +0000
                Re: Counted strings Ian Collins <ian-news@hotmail.com> - 2016-12-06 10:25 +1300
                Re: Counted strings BartC <bc@freeuk.com> - 2016-12-05 21:36 +0000
                Re: Counted strings jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-05 22:33 +0100
                Re: Counted strings "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-12-05 17:03 -0500
    Re: Counted strings supercat@casperkitty.com - 2016-12-04 08:57 -0800
    Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-04 20:19 +0100
      Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-04 20:24 +0100
        Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-04 20:37 +0100
          Re: Counted strings David Brown <david.brown@hesbynett.no> - 2016-12-04 21:04 +0100
            Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-04 21:22 +0100
              Re: Counted strings BartC <bc@freeuk.com> - 2016-12-04 22:37 +0000
              Re: Counted strings David Thompson <dave.thompson2@verizon.net> - 2016-12-10 22:42 -0500
                Re: Counted strings Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-10 23:17 -0800
                Re: Counted strings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 11:48 +0000
                Re: Counted strings Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-11 04:40 -0800
                Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-11 10:56 +0100
      Re: Counted strings Robert Wessel <robertwessel2@yahoo.com> - 2016-12-05 15:47 -0600
        Re: Counted strings Gareth Owen <gwowen@gmail.com> - 2016-12-05 22:01 +0000
          Re: Counted strings Robert Wessel <robertwessel2@yahoo.com> - 2016-12-05 22:28 -0600
        Re: Counted strings "Chris M. Thomasson" <invalid@invalid.invalid> - 2016-12-05 20:18 -0800
        Re: Counted strings Robert Spanjaard <spamtrap@arumes.com> - 2016-12-06 11:05 +0100
  Re: Counted strings luser droog <luser.droog@gmail.com> - 2016-12-04 13:13 -0800
  Re: Counted strings Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-05 09:30 -0800
    Re: Counted strings Keith Thompson <kst-u@mib.org> - 2016-12-05 09:41 -0800
      Re: Counted strings Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-06 11:19 -0800
        Re: Counted strings Keith Thompson <kst-u@mib.org> - 2016-12-06 11:44 -0800
  Re: Counted strings Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-10 10:29 -0800
    Re: Counted strings supercat@casperkitty.com - 2016-12-10 11:08 -0800

csiph-web