2012-04-27 81 views
2

有谁知道GNU GCC中libstdC++中basic_filebuf的默认缓冲区大小吗?我知道成员函数pubsetbuf(),我很确定缓冲区大小是实现定义的。在C内部很简单,从<cstdio>处取BUFSIZ。libstdC++中basic_filebuf的默认缓冲区大小

也许变量被称为extern_bufXSIZEintern_bufISIZE

+1

我开了头的basic_filebuf,并看看你,默认值是,哦,有什么新的闪亮的按钮,是这样吗? – PlasmaHH 2012-04-27 12:46:50

+0

到目前为止你是对的。谢谢!但也有点不礼貌。老实说。我只是没有找到正确的文件来看看里面。认为它不能是fstream/fstream.tcc,因为我查看了“basic_filebuf”的alwas!但正是这个文件,我必须看! – Peter 2012-04-27 13:39:20

回答

1

我找到了。 C++从C中获取BUFSIZ(请参阅参考资料)。文件fstreamfstream.tcc包括类别basic_filebuf

注:++的libstdc从GCC

从文件fstream.tcc文件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; 

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); 
    } 
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