473,508 Members | 4,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Oct 18 '06 #1
8 6108
On 2006-10-18, mi******@gmail.com <mi******@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
http://www.iovene.com
Oct 18 '06 #2
mi******@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<unsigned char>, though, since
you may not receive string data.

3. std::copy(newdata.begin(),
newdata.end(),
std::back_inserter(buffer));
Oct 18 '06 #3
On 18 Oct 2006 11:44:09 -0700 in comp.lang.c++, mi******@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.

Oct 18 '06 #4
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

Oct 18 '06 #5
Salvatore Iovene wrote:
On 2006-10-18, mi******@gmail.com <mi******@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

Oct 19 '06 #6

Nick Keighley schrieb:
Salvatore Iovene wrote:
On 2006-10-18, mi******@gmail.com <mi******@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

Oct 19 '06 #7
Salvatore Iovene wrote:
On 2006-10-18, mi******@gmail.com <mi******@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.
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
Oct 20 '06 #8
mi******@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:
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
Oct 20 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6229
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled....
4
6657
by: ma740988 | last post by:
A few days ago I recieved yet again advice on implementing a buffer of bytes. At issue: (part 1) how do I take the contents of a struct, then dump (used sparingly) it into a byte buffer. ...
2
6602
by: William Stacey | last post by:
Working with implementing a circular buffer for a producer/consumer deal. Have not done one in a while. The following seems to work. However, I remember and have seen other implementation that...
2
4028
by: Bill Sun | last post by:
Hi, I have a quetion about to refresh the ostringstream buffer: like this. ostringstream buffer; buffer << 245; // then the buffer.str() = "245"; ......
6
1484
by: nickdu | last post by:
I usually try to stay away from _alloca(). However, I'm considering using it for a logging function. Our current logging function maintains its own buffer which it grows to fit the string being...
28
3838
by: bwaichu | last post by:
Is it generally better to set-up a buffer (fixed sized array) and read and write to that buffer even if it is larger than what is being written to it? Or is it better to allocate memory and...
5
2839
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the...
4
3937
by: aki | last post by:
Hi all, i am writing codes for implementing network protocols. i have written a method which is receiving a packet from network. i have assumed that the packet i will receive will be of type...
0
3840
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
36
3761
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.