Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL buffer

Reply
Thread Tools

STL buffer

 
 
mike7411@gmail.com
Guest
Posts: n/a
 
      10-18-2006
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?

 
Reply With Quote
 
 
 
 
Salvatore Iovene
Guest
Posts: n/a
 
      10-18-2006
On 2006-10-18, <> 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?


You could subclass Vector or a List, and then overload the += operator
for that purpose.
Just an idea.

--
Salvatore Iovene
http://www.iovene.com
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      10-18-2006
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<unsigned char>, though, since
you may not receive string data.

3. std::copy(newdata.begin(),
newdata.end(),
std::back_inserter(buffer));
 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      10-18-2006
On 18 Oct 2006 11:44:09 -0700 in comp.lang.c++,
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.

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      10-18-2006
> 2. You should probably use a std::vector<unsigned 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

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      10-19-2006
Salvatore Iovene wrote:
> On 2006-10-18, <> 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?

>
> 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

 
Reply With Quote
 
ralph
Guest
Posts: n/a
 
      10-19-2006

Nick Keighley schrieb:

> Salvatore Iovene wrote:
> > On 2006-10-18, <> 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?

> >
> > 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

 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      10-20-2006
Salvatore Iovene wrote:

> On 2006-10-18, <> 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?

>
>
> 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:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      10-20-2006
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:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
buffer creates only read-only buffer? Neal Becker Python 0 01-08-2009 01:58 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
convert M bit buffer to N bit buffer runcyclexcski@yahoo.com C++ 2 03-26-2007 09:43 AM
How to know the buffer size and increase buffer size in c++ Raja C++ 12 06-21-2004 06:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57