STL buffer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike7411@gmail.com

    #1

    STL buffer

    I'm trying to create a program that will buffer data received in UDP
    packets.

    I'd like to use an STL object that will allow me to add on new data
    like this:

    buffer+=newdata ;

    I don't think I can use a string because I don't think it allows 0
    characters.

    Any ideas on what to use?

  • Salvatore Iovene

    #2
    Re: STL buffer

    On 2006-10-18, mike7411@gmail. com <mike7411@gmail .comwrote:
    I'm trying to create a program that will buffer data received in UDP
    packets.
    >
    I'd like to use an STL object that will allow me to add on new data
    like this:
    >
    buffer+=newdata ;
    >
    I don't think I can use a string because I don't think it allows 0
    characters.
    >
    Any ideas on what to use?
    You could subclass Vector or a List, and then overload the += operator
    for that purpose.
    Just an idea.

    --
    Salvatore Iovene

    Comment

    • red floyd

      #3
      Re: STL buffer

      mike7411@gmail. com wrote:
      I'm trying to create a program that will buffer data received in UDP
      packets.
      >
      I'd like to use an STL object that will allow me to add on new data
      like this:
      >
      buffer+=newdata ;
      >
      I don't think I can use a string because I don't think it allows 0
      characters.
      >
      Any ideas on what to use?
      >
      1. Yes, std::string allows 0 characters.

      2. You should probably use a std::vector<uns igned char>, though, since
      you may not receive string data.

      3. std::copy(newda ta.begin(),
      newdata.end(),
      std::back_inser ter(buffer));

      Comment

      • David Harmon

        #4
        Re: STL buffer

        On 18 Oct 2006 11:44:09 -0700 in comp.lang.c++, mike7411@gmail. com
        wrote,
        >I don't think I can use a string because I don't think it allows 0
        >characters.
        std::string can contain '\0' characters, no problem.

        Comment

        • Michael

          #5
          Re: STL buffer

          2. You should probably use a std::vector<uns igned char>, though, since
          you may not receive string data.
          You might want std::deque, since you'll probably want to pop data out
          of the buffer too.

          Michael

          Comment

          • Nick Keighley

            #6
            Re: STL buffer

            Salvatore Iovene wrote:
            On 2006-10-18, mike7411@gmail. com <mike7411@gmail .comwrote:
            I'm trying to create a program that will buffer data received in UDP
            packets.

            I'd like to use an STL object that will allow me to add on new data
            like this:

            buffer+=newdata ;

            I don't think I can use a string because I don't think it allows 0
            characters.

            Any ideas on what to use?
            >
            You could subclass Vector or a List, and then overload the += operator
            for that purpose.
            Just an idea.
            subclass == derive from?

            can you derive from the std containers?

            --
            Nick Keighley

            Comment

            • ralph

              #7
              Re: STL buffer


              Nick Keighley schrieb:
              Salvatore Iovene wrote:
              On 2006-10-18, mike7411@gmail. com <mike7411@gmail .comwrote:
              >
              I'm trying to create a program that will buffer data received in UDP
              packets.
              >
              I'd like to use an STL object that will allow me to add on new data
              like this:
              >
              buffer+=newdata ;
              >
              I don't think I can use a string because I don't think it allows 0
              characters.
              >
              Any ideas on what to use?
              You could subclass Vector or a List, and then overload the += operator
              for that purpose.
              Just an idea.
              >
              subclass == derive from?
              >
              can you derive from the std containers?
              You can. But you don't want to.

              ralpe

              Comment

              • Thomas Matthews

                #8
                Re: STL buffer

                Salvatore Iovene wrote:
                On 2006-10-18, mike7411@gmail. com <mike7411@gmail .comwrote:
                >
                >>I'm trying to create a program that will buffer data received in UDP
                >>packets.
                >>
                >>I'd like to use an STL object that will allow me to add on new data
                >>like this:
                >>
                >>buffer+=newda ta;
                >>
                >>I don't think I can use a string because I don't think it allows 0
                >>characters.
                >>
                >>Any ideas on what to use?
                >
                >
                You could subclass Vector or a List, and then overload the += operator
                for that purpose.
                Just an idea.
                >
                In general, you don't want to use a linked list for receiving
                packet data. Way too slow.

                --
                Thomas Matthews

                C++ newsgroup welcome message:

                C++ Faq: http://www.parashift.com/c++-faq-lite
                C Faq: http://www.eskimo.com/~scs/c-faq/top.html
                alt.comp.lang.l earn.c-c++ faq:

                Other sites:
                http://www.josuttis.com -- C++ STL Library book
                http://www.sgi.com/tech/stl -- Standard Template Library

                Comment

                • Thomas Matthews

                  #9
                  Re: STL buffer

                  mike7411@gmail. com wrote:
                  I'm trying to create a program that will buffer data received in UDP
                  packets.
                  >
                  I'd like to use an STL object that will allow me to add on new data
                  like this:
                  >
                  buffer+=newdata ;
                  >
                  I don't think I can use a string because I don't think it allows 0
                  characters.
                  >
                  Any ideas on what to use?
                  >
                  If you use std::vector, pre-allocate the size for the average
                  packet. You don't want std::vector to reallocate while you
                  are receiving data.

                  Also, search the web for "double buffering". A minimum of
                  two buffers used for send and receiving.

                  Many embedded systems pre-allocate a space for the data
                  packets. These are arrays of unsigned chars. The goal
                  is to haul the data in as fast as possible, then analyze
                  it. An array has the minimal access times and least
                  overhead.

                  --
                  Thomas Matthews

                  C++ newsgroup welcome message:

                  C++ Faq: http://www.parashift.com/c++-faq-lite
                  C Faq: http://www.eskimo.com/~scs/c-faq/top.html
                  alt.comp.lang.l earn.c-c++ faq:

                  Other sites:
                  http://www.josuttis.com -- C++ STL Library book
                  http://www.sgi.com/tech/stl -- Standard Template Library

                  Comment

                  Working...