473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Continuously concatenating binary data

I have an application, where I continuously get new binary data input, in
the form of a char*. This data comes from the Windows Multimedia wave input
functions, but that's not important. What it means is that every 2 seconds,
I need to add 22050 bytes to an ever expanding buffer. I have no idea at the
beginning how large this buffer would need to be.

Now there are several possibilities to do is, as I see it:
1. Just make the buffer a void* (or char*), and realloc it every 2 seconds,
copying the new data to the end. This isn't a good idea of course, because
realloc will become very expensive as the buffer grows.
2. Use something like this, with ssBuffer an ostringstream:
ssBuffer << newdata;
Then just read out the entire stream at the end.
I don't know how ostringstream manages buffer growth, so this might not be
any better (performance-wise) than the realloc approach.
3. Do the same as above, but with an ofstream. This can handle really huge
input (although I don't expect input to be more than 10-15 seconds of audio
data ever), and should be reasonably efficient since Windows buffers file
I/O, but it does require the user to have writing rights whereever I'm going
to put this file.
4. Copy every 2 seconds of data into it's own 'minibuffer', add those to a
std::list, and at the end create a large buffer only once, copying all
individual pieces into it.

What would be the best approach in your opinions? Or perhaps you have an
even better one that I didn't think of.

Thanks in advance.

--
Unforgiven

A: Top Posting!
Q: What is the most annoying thing on Usenet?

Jul 19 '05 #1
5 4009
"Unforgiven " <ja*******@hotm ail.com> wrote...
I have an application, where I continuously get new binary data input, in
the form of a char*. This data comes from the Windows Multimedia wave input functions, but that's not important. What it means is that every 2 seconds, I need to add 22050 bytes to an ever expanding buffer. I have no idea at the beginning how large this buffer would need to be.
What do you need the buffer for? Do you use it right away? Does
the buffer have to be contiguous during your input?

If not, use a list<your22050b ytes>. I suspect that even if you do
need to use the "stream" right away, the list is quick enough for
all your streaming needs.
[...]


Victor

Jul 19 '05 #2
I think having a vector<char> should be good enough. vectors should
not be more than twice worse than array accesses - They are pretty
fast. Also they would allow you to expand as more data comes in.

You can look at the vector allocation strategy - it doubles its size
wheneve there is an overflow kindof situation.

-nitin
Jul 19 '05 #3
Just a thought:

If your user have small amount of memory or record large
amount of data, all your malloc/realloc will turn into
swap disk i/o.

It would be no differents than stream approach.
In fact stream give you better control on amount of memory
your app needs.
--
The source is out there. Browse and document open/share source
projects such as Apache, Tcl, Ethereal, Mozilla, .Net SSCLI.
http://www.slink-software.com

"Victor Bazarov" <v.********@att Abi.com> wrote in message news:<J2******* *************@r wcrnsc51.ops.as p.att.net>...
"Unforgiven " <ja*******@hotm ail.com> wrote...
I have an application, where I continuously get new binary data input, in
the form of a char*. This data comes from the Windows Multimedia wave

input
functions, but that's not important. What it means is that every 2

seconds,
I need to add 22050 bytes to an ever expanding buffer. I have no idea at

the
beginning how large this buffer would need to be.


What do you need the buffer for? Do you use it right away? Does
the buffer have to be contiguous during your input?

If not, use a list<your22050b ytes>. I suspect that even if you do
need to use the "stream" right away, the list is quick enough for
all your streaming needs.
[...]


Victor

Jul 19 '05 #4
Nitin Rajput wrote:
I think having a vector<char> should be good enough. vectors should
not be more than twice worse than array accesses - They are pretty
fast. Also they would allow you to expand as more data comes in.

You can look at the vector allocation strategy - it doubles its size
wheneve there is an overflow kindof situation.


A raw char vector is probably not a good idea. As the vector
grows you not only start moving large amounts of data about,
but run the risk of being unable to allocate enough
contiguous memory.

Vectors are alright if you know in advance that the number
of elements going to be used is reasonably small (a few
thousand at most).

A list of vectors holding each 2 seconds worth of data is
probably sufficient in this case.

Jul 19 '05 #5
lilburne wrote:
Nitin Rajput wrote:
I think having a vector<char> should be good enough. vectors should
not be more than twice worse than array accesses - They are pretty
fast. Also they would allow you to expand as more data comes in.

You can look at the vector allocation strategy - it doubles its size
wheneve there is an overflow kindof situation.


A raw char vector is probably not a good idea. As the vector
grows you not only start moving large amounts of data about,
but run the risk of being unable to allocate enough
contiguous memory.


This is one of the reasons I didn't even give a vector as an option.
Doubling size may limit reallocs, but when you start to get into the really
big amounts of data, it could potentially waste a *lot* of memory.

Another problem with any approach that uses contiguous memory (which would
include C-style arrays, std::vector and I suppose also memory-based streams
such as std::ostringstr eam) is that freeing memory (a realloc is basically a
malloc, memcpy, free sequence) tends to be very expensive on Windows. I
believe it has to do with the memory manager wanting to pack the heap after
each free (I once had to deallocate a 300MB (don't ask) 4-dimensional jagged
array of bools (bool****) and it took nearly 5 minutes on a Pentium III
600MHz)

Contiguous memory should not be much of a problem. All we need is contiguous
address space, not actual contiguous memory, thanks to the virtue of virtual
memory. And because is the heap is packed at least every so often, it
shouldn't give any problems soon.

--
Unforgiven

A: Top Posting!
Q: What is the most annoying thing on Usenet?

Jul 19 '05 #6

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

Similar topics

13
15255
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
2
2530
by: Lisa Pearlson | last post by:
Hi, My php application (on Apache/Linux) needs to do the following: The PHP script receives a request from a client (binary), asking for certain records of data. My PHP script loops through all records and sends each of them ONE BY ONE. After each record that my server script sends, it waits for the client to confirm proper reception with an ACK (binary digit). When there are no more records, my server script sends the client a binary
4
2349
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I can´t see them in the debugger). After encoding the string (the sameone which complete value is not visible from the debugger) all the values can be seen but they are spaced by big amounts of zeros and use more that the 2048 bytes allocated. It is like if...
2
7782
by: Raed Sawalha | last post by:
Hello: I have 2 windows application 1st one is periodically writing specific data to XML file , the 2nd application has a dialog with DataGrid , the datagrid filled with information in the XML generated by 1st application and should be updated as soon as the XML file is update, so I decide to code a continously running thread that checks the XML every specific time and refresh the contents of datagrid the question : 1. How can I code a...
0
355
by: nandha | last post by:
H I have a doubt in VC++ regarding file reading and displaying in the GUI (Dialog I have a binary file, which contains several piece of information , i have to read the information continuously from the file and continue to display the information in the GUI, i have created a GUI , using dialog based and having a list box in that dialog, After reading a part of information i have to display in GUI, and again i have to keep on reading ...
4
11793
by: Elena | last post by:
Hi, I am filling in a combobox. I would like to concatenate two fields into the data combo box and display "last name, first name" I tried to displaymember = "employee_last_name" & ", " & "employee_last_name", but it did not like that. I can fill the combo box with either the first or the last, but I cannot manage to concatenate it.
21
2328
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to solve in this small code, I can solve it on my own program...you don't want to have head-ache :-) So, the problem excatly is, I built an array..just like this one.
4
1590
by: paulb | last post by:
I was wondering if it is possible to continuously query a real-time datastream using SQL Server. Does anyone have any experience of this? I have found LINUX based systems such as Borealis and STREAM. I would prefer to use a Windows based system as the program using the query results is Windows based.
3
1825
by: bgold12 | last post by:
I'm curious about how websites deal with the problem of continuously growing data. For example, there are many forums that preserve all posts for many years back, and are continuously receiving and storing new posts all the time. No website has access to an infinite amount of storage space, so: What kind of buffer (i.e. space available) do they like to have, or in other words, how much time do they have before they would run out of...
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8813
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.