Default buffer size of basic_filebuf within libstdc++
Asked Answered
K

2

2

Does anyone know the default buffer size for basic_filebuf in libstdc++ from the GNU GCC? I know the member function pubsetbuf() and I am pretty sure the the buffer size is implementation-defined. Within C it is simple, take BUFSIZ from <cstdio>.

Maybe the variable are called extern_buf, XSIZE, intern_buf or ISIZE?

Kalmick answered 27/4, 2012 at 12:38 Comment(2)
I opened the header for basic_filebuf and had a look for you, and the default is, oh, what shiny new button is this?Mussulman
You are right, so far. Thank you! But also a little bit impolite. Honestly. I just did't find the correct file to take a look inside. Thought it can't be fstream/fstream.tcc, because I looked alwas for "basic_filebuf"! But exactly this files I have to look!Kalmick
B
2

8 Kilobytes

It might vary per implementation. I was curious about this myself because of a new personal project I started. My search began in stdio.h because of Peter's answer. A simple:

cat /usr/include/stdio.h | grep -i bufsiz yielded a redefinition.

grep -rwnl /usr/include/ -e first _IO_BUFSIZ (defined in libio.h) was appended and then _G_BUFSIZ (defined in _G_config.h). Redefinitions stopped there.

grep -i _g_bufsiz /usr/include/_G_config.h

Bernadinebernadotte answered 4/3, 2016 at 13:58 Comment(0)
K
1

I found it. C++ takes the BUFSIZ from C (see ). The files fstream and fstream.tcc includes the class basic_filebuf.

Note: LIBSTDC++ from GCC

from file fstream

#include <istream>
#include <ostream>
#include <bits/codecvt.h>
#include <cstdio>             // For BUFSIZ
#include <bits/basic_file.h>  // For __basic_file, __c_lock
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <string>             // For std::string overloads.
#endif


/**
 *  Actual size of internal buffer. This number is equal to the size
 *  of the put area + 1 position, reserved for the overflow char of
 *  a full area.
 */
size_t          _M_buf_size;

from file fstream.tcc

template<typename _CharT, typename _Traits>
    basic_filebuf<_CharT, _Traits>::
    basic_filebuf() : __streambuf_type(), _M_lock(), _M_file(&_M_lock),
    _M_mode(ios_base::openmode(0)), _M_state_beg(), _M_state_cur(),
    _M_state_last(), _M_buf(0), _M_buf_size(BUFSIZ),
    _M_buf_allocated(false), _M_reading(false), _M_writing(false), _M_pback(), 
    _M_pback_cur_save(0), _M_pback_end_save(0), _M_pback_init(false),
    _M_codecvt(0), _M_ext_buf(0), _M_ext_buf_size(0), _M_ext_next(0),
    _M_ext_end(0)
    {
      if (has_facet<__codecvt_type>(this->_M_buf_locale))
    _M_codecvt = &use_facet<__codecvt_type>(this->_M_buf_locale);
    }
Kalmick answered 27/4, 2012 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.