美文网首页
Bitcoind SetupEnvironment

Bitcoind SetupEnvironment

作者: 周倜吉 | 来源:发表于2018-09-04 10:48 被阅读0次
void SetupEnvironment()
{
#ifdef HAVE_MALLOPT_ARENA_MAX//判断某个宏是否被定义,若已定义,执行随后的语句
    // glibc-specific: On 32-bit systems set the number of arenas to 1.
    // By default, since glibc 2.10, the C library will create up to two heap
    // arenas per core. This is known to cause excessive virtual address space
    // usage in our usage. Work around it by setting the maximum number of
    // arenas to 1.
    if (sizeof(void*) == 4) {//判断是否是32位的系统,void*是空白指针,32位系统中占用4个字节;
        mallopt(M_ARENA_MAX, 1);/*控制 内存分配的函数param 的取值可以为M_CHECK_ACTION、
M_MMAP_MAX、M_MMAP_THRESHOLD、M_MXFAST
(从glibc2.3起)、M_PERTURB(从glibc2.4起)、M_TOP_PAD、M_TRIM_THRESHOLD。
此处解释param取值为M_MXFAST的情况;value是以 字节为单位的。
比如设置M_MMAP_THRESHOLD选项可以设置启用mmap申请malloc字节数阀值,设置-1是不启用mmap
这些选项可以通过mallopt()进行设置*/
    }
#endif//#if, #ifdef, #ifndef这些条件命令的结束标志.
    // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
    // may be invalid, in which case the "C" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
    //defined          与#if, #elif配合使用,判断某个宏是否被定义
/*defined用来测试某个宏是否被定义。defined(name): 若宏被定义,则返回1,否则返回0。
它与#if、#elif、#else结合使用来判断宏是否被定义,乍一看好像它显得多余, 
因为已经有了#ifdef和#ifndef。
defined可用于在一条判断语句中声明多个判别条件;#ifdef和#ifndef则仅支持判断一个宏是否定义。*/
    try {
        std::locale(""); /* 在编程中我们常用,我们通过locale设定程序中语言编码,日期格式,数字格式以及其他区域相关设置
Raises a runtime error if current locale is invalid;*/
    } catch (const std::runtime_error&) {/*异常处理模型的trycatch使用语法,其中catch关键字
是用来定义catch block的,它后面带一个参数,用来与异常对象的数据类型进行匹配。注意catch
关键字只能定义一个参数,因此每个catch block只能是一种数据类型的异常对象的错误处理模块。*/
        setenv("LC_ALL", "C", 1);
    }/*setenv(改变或增加环境变量)
  相关函数 getenv,putenv,unsetenv
  表头文件 #include<stdlib.h>
  定义函数 int setenv(const char *name,const char * value,int overwrite);
  函数说明 setenv()用来改变或增加环境变量的内容。
*/
#endif
    // The path locale is lazy initialized and to avoid deinitialization errors
    // in multithreading environments, it is set explicitly by the main thread.
    // A dummy locale is used to extract the internal default locale, used by
    // fs::path, which is then used to explicitly imbue the path.
    std::locale loc = fs::path::imbue(std::locale::classic());
    fs::path::imbue(loc);
}

相关文章

网友评论

      本文标题:Bitcoind SetupEnvironment

      本文链接:https://www.haomeiwen.com/subject/yuobwftx.html