logo
down
shadow

C++-What is the need of both buffer and stream?


C++-What is the need of both buffer and stream?

By : Valentina Quiroga Fo
Date : November 22 2020, 09:00 AM
With these it helps Ok lets lets start from the scratch suppose you want to work with files. For this purpose you would have to manage how the data is entered into your file and if the sending of data into the file was successful or not, and all other basic working problems. Now either you can manage all that on your own which would take a lots a time and hard work or What you can do is you can use a stream.
Yes, you can allocate a stream for such purposes. Streams work with abstraction mechanism i.e. we c++ programmers don't know how they are working but we only know that we are at the one side of a stream (on our program's side) we offer our data to the stream and it has the responsibility to transfer data from one end to the other (file's side)
code :
ofstream file("abc.txt"); //Here an object of output file stream is created
file<<"Hello";            //We are just giving our data to stream and it transfers that
file.close();             //The closing of file


Share : facebook icon twitter icon
c++ boost would async_read_some be blocked by buffer if the buffer is being fill by a data stream?

c++ boost would async_read_some be blocked by buffer if the buffer is being fill by a data stream?


By : Ari Ardiana
Date : March 29 2020, 07:55 AM
wish help you to fix your issue For TCP, async_read_some might retrieve only part of the stream, and there are no blocking in the sense of user program.
Is it more effective to buffer an output stream than an input stream in Java?

Is it more effective to buffer an output stream than an input stream in Java?


By : Naswari Lala
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , When you read a file, the filesystem and devices below it do various levels of caching. They almost never read one byte at at time; they read a block. On a subsequent read of the next byte, the block will be in cache and so will be much faster.
It stands to reason then that if your buffer size is the same size as your block size, buffering the input stream doesn't actually gain you all that much (it saves a few system calls, but in terms of actual physical I/O it doesn't save you too much).
Icecast relay stream can buffer a progressive audio stream

Icecast relay stream can buffer a progressive audio stream


By : user2018430
Date : March 29 2020, 07:55 AM
it should still fix some issue Icecast does buffer streams. When a client connects, the buffer data is flushed as fast as Icecast can loop around and send data.
Icecast can also relay existing streams. From the documentation:
code :
<relay>
    <server>192.168.1.11</server>
    <port>8001</port>
    <mount>/example.ogg</mount>
    <local-mount>/different.ogg</local-mount>
    <relay-shoutcast-metadata>0</relay-shoutcast-metadata>
</relay>
Stream buffer size less than input stream, but no immediate segmentation fault

Stream buffer size less than input stream, but no immediate segmentation fault


By : user2553252
Date : March 29 2020, 07:55 AM
To fix the issue you can do For the first part of your question,it has to do with page size in OS. And ofcourse, that code causes "undefined behavior".
This answer gives a really good idea: why doesn't my program crash when I write past the end of an array?
code :
int getchar ( void );
Custom input stream. Stream buffer and underflow method

Custom input stream. Stream buffer and underflow method


By : samiovich
Date : March 29 2020, 07:55 AM
will help you From my old C++ experience a stream buf is the underlying buffer for the stream. When the stream needs more data it calls underflow. Inside this method you are suppose to read from your source and setg. When the stream has data to be written back to the source it calls overflow. Inside this method you read from the stream,write back to your source and setp. For example if you are reading the data from a socket in your streambuf
code :
socketbuf::int_type socketbuf::underflow(){
  int bytesRead = 0;
  try{
    bytesRead = soc->read(inbuffer,BUFFER_SIZE-1,0);
    if( bytesRead <= 0 ){
      return traits_type::eof();
    }
  }catch(IOException ioe){
    cout<<"Unable to read data"<<endl;
    return traits_type::eof();
  }
  setg(inbuffer,inbuffer,inbuffer+bytesRead);
  return traits_type::to_int_type(inbuffer[0]);
}

socketbuf::int_type socketbuf::overflow(socketbuf::int_type c){
  int bytesWritten = 0;
  try{
    if(pptr() - pbase() > 0){
      bytesWritten = soc->write(pbase(),(pptr() - pbase()),0);
      if( bytesWritten <= 0 )  return traits_type::not_eof(c);
    }
  }catch(IOException ioe){
    cout<<"Unable to write data"<<endl;
    return traits_type::eof();
  }
  outbuffer[0] = traits_type::to_char_type(c);
  setp(outbuffer,outbuffer+1,outbuffer+BUFFER_SIZE);
  return traits_type::not_eof(c);
}
result = traits_type::to_int_type('+'); // <-- this was added
if (result != 10)// <-- add this in addition
    result = traits_type::to_int_type('+'); // <-- this was added
Related Posts Related Posts :
  • Passing buffer between two terminals (Named Pipe)
  • C++ parse sub-string to integer
  • Create stereo context for modern opengl
  • Memory leak, when using GLM
  • Get Control under cursor
  • Is this proper behavior? std::map iterator invalidation
  • 2D isometric engine - Math problems - Cube selection - diamond shape map
  • Open second window in Qt
  • Stack Overflow error with Vectors
  • Pure Virtual Friend Class
  • Object initialization syntax in C++
  • Variable undefined error
  • C++ tolower/toupper char pointer
  • Overhead with std::function
  • Is there a way to make a loop that get user input but doesn't stop if the user doesn't input anything?
  • OpenCV in cmake-based project: checking for contrib modules
  • shared_ptr vs unique_ptr uses in classes and children
  • MFC dialog Border padding changed after switching from VS2010 to 2012 or later
  • String rotator in C++ (bitwise rotation)
  • Custom sort vector of pair based on their values
  • Pointer to const overloaded member function
  • how to avoid this for-loop mess in c++?
  • Can the state of a standard C++ iostream manipulator be polled?
  • How to make sure a data type is as large as it needs to be in C++
  • Why is my first ofstream output in my else block missing the fill character?
  • Returning static/ normal arrays in recursion/another function
  • c++, why use const std::string & parameterName?
  • expression did not evaluate to a constant in C++ VS
  • Owner object that takes pre-created values ? Wrong design?
  • Cannot use Macro in a C++ constructor?
  • vector is loosing mat4 information
  • Invalid declarator before with map of struct?
  • std::initializer_list to return member variables returns incorrect values
  • Unable to use Boost + Qt in Mac
  • Passing template function and overload as function argument
  • non standard extension warning when searching in a vector of unique_ptrs
  • Qt Windows x64 build succeeds in IDE but not on the command line
  • condition_variable::wait_for method not returning - even after the timeout
  • boost::asio usage in self-contained class
  • CGAL triangulation with constraints changes points coords
  • How to resolve an ambiguous reference caused by a conflicting identifier from inline namespace
  • When UTF8 emoji character is removed from NSMutableString the conversion to std::string fails
  • XOR of two strings of 0s and 1s
  • OpenCV: check if pixel is within bounding rectangle, separated by contour line
  • geany: C++ Including libraries and headers
  • How can I combine an in place transformation, and a copy transformation?
  • error of the assigning unique ptr in another thread
  • SetArrayArgument, is it really the last or lenth?
  • What is the role of "&" and "*" on operator overloading?
  • C++ passing a nested unordered_map by reference and manipulating it
  • Prefer unordered_set over vector
  • CUDA, Qt creator and Mac
  • Heroku / Rails: can't set path to vendorized dependencies
  • Using self made libraries in Visual Studio
  • Bypass trigger of OnFocus/GetFocus event if the application window loses activation c++
  • CURLpp, segmentation fault
  • Exclusive checkbox in QListView
  • Firemonkey: TLabel text truncated despite autosize property true
  • How to prevent constructor from casting argument types in c++?
  • Why can't I construct a gsl::span with a brace-enclosed initializer list
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co