2

GNU GCCのlibstdc ++のbasic_filebufのデフォルトのバッファサイズを知っている人はいますか? 私はメンバ関数 pubsetbuf() を知っており、バッファ サイズは実装定義であると確信しています。C 内では簡単です。 から BUFSIZ を取得し<cstdio>ます。

おそらく、変数はextern_bufXSIZEintern_buf、またはISIZEと呼ばれますか?

4

2 に答える 2

1

見つけた。C++ は C から BUFSIZ を取得します ( を参照)。ファイルfstreamおよびfstream.tccには、クラスbasic_filebufが含まれています。

注: GCC の LIBSTDC++

ファイル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;

ファイル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);
    }
于 2012-04-27T13:48:13.907 に答える
1

8キロバイト

実装ごとに異なる場合があります。私が始めた新しい個人的なプロジェクトのため、私自身もこれに興味がありました。stdio.hピーターの答えから、私の検索が始まりました。シンプルな:

cat /usr/include/stdio.h | grep -i bufsiz再定義をもたらしました。

grep -rwnl /usr/include/ -e最初_IO_BUFSIZに ( で定義libio.h) が追加され、次に_G_BUFSIZ( で定義) が追加されました_G_config.h。再定義はそこで止まりました。

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

于 2016-03-04T13:58:49.370 に答える