************************关于前置申明 && 智能指针的问题

u011102675 2013-08-04 11:17:33
最近遇到一个问题,求支教

如果类A已经用智能指针包了一层,如下:
class TestA
{


}

typedef boost::shared<TestA> TestAPtr;

=====================================================================

在另外一个类里面需要用到这个类A的前置申明,该怎么写这个前置申明了?

...全文
305 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
u011102675 2013-08-05
  • 打赏
  • 举报
回复
引用 12 楼 max_min_ 的回复:
[quote=引用 11 楼 u011102675 的回复:] [quote=引用 10 楼 max_min_ 的回复:] [quote=引用 9 楼 u011102675 的回复:] TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
内存泄露是自己分配的堆空间没有及时释放而引起的 你这里唯一一处申请堆空间的就是 new一个testA对象而已, 你手动写一个析构函数出来释放掉,看看内存情况, 如果有内存泄露,之前定义也是有的! 不可能会是因为你前置定义引起导致内存泄露的, 我不晓得你是怎么测试的[/quote] 利用测试内存泄漏软件测试的[/quote] 不要默认的析构函数, 你自己也一个,要delete掉你new出来对象,再测试[/quote] 我两个类用的都是智能指针...
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
引用 11 楼 u011102675 的回复:
[quote=引用 10 楼 max_min_ 的回复:] [quote=引用 9 楼 u011102675 的回复:] TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
内存泄露是自己分配的堆空间没有及时释放而引起的 你这里唯一一处申请堆空间的就是 new一个testA对象而已, 你手动写一个析构函数出来释放掉,看看内存情况, 如果有内存泄露,之前定义也是有的! 不可能会是因为你前置定义引起导致内存泄露的, 我不晓得你是怎么测试的[/quote] 利用测试内存泄漏软件测试的[/quote] 不要默认的析构函数, 你自己也一个,要delete掉你new出来对象,再测试
u011102675 2013-08-05
  • 打赏
  • 举报
回复
引用 10 楼 max_min_ 的回复:
[quote=引用 9 楼 u011102675 的回复:] TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
内存泄露是自己分配的堆空间没有及时释放而引起的 你这里唯一一处申请堆空间的就是 new一个testA对象而已, 你手动写一个析构函数出来释放掉,看看内存情况, 如果有内存泄露,之前定义也是有的! 不可能会是因为你前置定义引起导致内存泄露的, 我不晓得你是怎么测试的[/quote] 利用测试内存泄漏软件测试的
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
引用 9 楼 u011102675 的回复:
TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
内存泄露是自己分配的堆空间没有及时释放而引起的 你这里唯一一处申请堆空间的就是 new一个testA对象而已, 你手动写一个析构函数出来释放掉,看看内存情况, 如果有内存泄露,之前定义也是有的! 不可能会是因为你前置定义引起导致内存泄露的, 我不晓得你是怎么测试的
u011102675 2013-08-05
  • 打赏
  • 举报
回复
TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
引用 7 楼 u011102675 的回复:
[quote=引用 6 楼 max_min_ 的回复:] [quote=引用 5 楼 u011102675 的回复:] [quote=引用 4 楼 max_min_ 的回复:]

// 申明
class TestA;
typedef boost::shared<TestA> TestAPtr;

这种方法会导致循环引用,会有内存泄漏的,已经测试过了[/quote] 循环引用 ,带有内存泄露? 这两个问题和你这样前置申明应该没有影响的吧?亲[/quote] 稍等,我再写段测试代码[/quote] 等你测试结果
u011102675 2013-08-05
  • 打赏
  • 举报
回复
引用 6 楼 max_min_ 的回复:
[quote=引用 5 楼 u011102675 的回复:] [quote=引用 4 楼 max_min_ 的回复:]

// 申明
class TestA;
typedef boost::shared<TestA> TestAPtr;

这种方法会导致循环引用,会有内存泄漏的,已经测试过了[/quote] 循环引用 ,带有内存泄露? 这两个问题和你这样前置申明应该没有影响的吧?亲[/quote] 稍等,我再写段测试代码
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
引用 5 楼 u011102675 的回复:
[quote=引用 4 楼 max_min_ 的回复:]

// 申明
class TestA;
typedef boost::shared<TestA> TestAPtr;

这种方法会导致循环引用,会有内存泄漏的,已经测试过了[/quote] 循环引用 ,带有内存泄露? 这两个问题和你这样前置申明应该没有影响的吧?亲
u011102675 2013-08-05
  • 打赏
  • 举报
回复
引用 4 楼 max_min_ 的回复:

// 申明
class TestA;
typedef boost::shared<TestA> TestAPtr;

这种方法会导致循环引用,会有内存泄漏的,已经测试过了
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
问题解决了? 是前置申明引起的内存泄漏么? 还有 左上角, 左下角 都是结贴按钮, 问题解决了,结贴是个好习惯! 方便论坛更新
u011102675 2013-08-05
  • 打赏
  • 举报
回复
引用 15 楼 ri_aje 的回复:
[quote=引用 9 楼 u011102675 的回复:] TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
我也试了一下,是有内存泄漏,而且应该有。 你这个情况是循环引用的变体,c++ 智能指针处理不了循环引用的情况,需要靠程序员自己注意。 在这个例子里 TestBPtr b; 和 TestA::TestBPtr _b; 引用的是同一个 TestB 对象。main 结束析构局部对象的时候,标准只保证析构前者,前者的析构函数会检测当前该智能指针管理的 TestB 对象的引用次数,此时是 2,然后将其递减 1,就完成析构了。另一次递减的机会要在析构 TestA::TestBPtr _b; 的时候才出现,而后者的析构又间接依赖于 TestB 析构函数的调用。因此形成一种类似死锁的局面。 标准给的解决方法是在 TestA 内部使用 weak_ptr,不要再次使用 shared_ptr,这样能够打破这种循环依赖的关系。例子程序如下。主要的修改在于 (1) TestA::_b 的类型改用 std::weak_ptr<TestB>. (2) TestA::show 使用 TestA::_b 的时候需要先 lock,这是标准要求的。 (3) 去掉了 namespace logserver 对于 TestB 的包装。因为 TestA.h 里面前向声明的时候只写了 struct TestB;,这只能声明 global namespace 中的 TestB,后者和 logserver::TestB 不是一个东西。实际上编译器应该给出编译错误才对。 (4) TestA/TestB 的析构函数增加了打印语句,主要是为了显示对象正确析构的动作。 用 valgrind 测了一下,没有发现内存泄漏。

// TestA.h
#ifndef TESTA_H
#define TESTA_H

#include <memory>
#include <iostream>

struct TestB;
struct TestA
{
   ~TestA () { std::cout << "~TestA" << std::endl; }

    std::weak_ptr<TestB> _b;
    void set(std::weak_ptr<TestB> B);
    void show();
};

typedef std::shared_ptr<TestA> TestAPtr;

#endif

// TestA.cpp
#include "TestA.h"
#include "TestB.h"
 
void TestA::set(std::weak_ptr<TestB> B)
{
    _b = B;
}
 
void TestA::show()
{
    _b.lock()->show();
}

// TestB.h
#ifndef TESTB_H
#define TESTB_H

#include "TestA.h"
#include <iostream>

struct TestB
{
    TestAPtr _a;
   ~TestB () { std::cout << "~TestB" << std::endl; }

    void create_a()
    {
        TestAPtr p(new TestA());
        _a = p;
    }

    TestAPtr get_a()
    {
        return _a;
    }

    void show()
    {
     std::cout<<"a 调用 b 的接口"<<std::endl;
    }
};

typedef std::shared_ptr<TestB> TestBPtr;

#endif

// main.cpp
#include "TestB.h"

int main ()
{
 TestBPtr b(new TestB());
 b->create_a();
 b->get_a()->set(b);
 b->get_a()->show();
}
[/quote] 经过测试,问题得到解决。十分感谢
ri_aje 2013-08-05
  • 打赏
  • 举报
回复
引用 9 楼 u011102675 的回复:
TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
我也试了一下,是有内存泄漏,而且应该有。 你这个情况是循环引用的变体,c++ 智能指针处理不了循环引用的情况,需要靠程序员自己注意。 在这个例子里 TestBPtr b; 和 TestA::TestBPtr _b; 引用的是同一个 TestB 对象。main 结束析构局部对象的时候,标准只保证析构前者,前者的析构函数会检测当前该智能指针管理的 TestB 对象的引用次数,此时是 2,然后将其递减 1,就完成析构了。另一次递减的机会要在析构 TestA::TestBPtr _b; 的时候才出现,而后者的析构又间接依赖于 TestB 析构函数的调用。因此形成一种类似死锁的局面。 标准给的解决方法是在 TestA 内部使用 weak_ptr,不要再次使用 shared_ptr,这样能够打破这种循环依赖的关系。例子程序如下。主要的修改在于 (1) TestA::_b 的类型改用 std::weak_ptr<TestB>. (2) TestA::show 使用 TestA::_b 的时候需要先 lock,这是标准要求的。 (3) 去掉了 namespace logserver 对于 TestB 的包装。因为 TestA.h 里面前向声明的时候只写了 struct TestB;,这只能声明 global namespace 中的 TestB,后者和 logserver::TestB 不是一个东西。实际上编译器应该给出编译错误才对。 (4) TestA/TestB 的析构函数增加了打印语句,主要是为了显示对象正确析构的动作。 用 valgrind 测了一下,没有发现内存泄漏。

// TestA.h
#ifndef TESTA_H
#define TESTA_H

#include <memory>
#include <iostream>

struct TestB;
struct TestA
{
   ~TestA () { std::cout << "~TestA" << std::endl; }

    std::weak_ptr<TestB> _b;
    void set(std::weak_ptr<TestB> B);
    void show();
};

typedef std::shared_ptr<TestA> TestAPtr;

#endif

// TestA.cpp
#include "TestA.h"
#include "TestB.h"
 
void TestA::set(std::weak_ptr<TestB> B)
{
    _b = B;
}
 
void TestA::show()
{
    _b.lock()->show();
}

// TestB.h
#ifndef TESTB_H
#define TESTB_H

#include "TestA.h"
#include <iostream>

struct TestB
{
    TestAPtr _a;
   ~TestB () { std::cout << "~TestB" << std::endl; }

    void create_a()
    {
        TestAPtr p(new TestA());
        _a = p;
    }

    TestAPtr get_a()
    {
        return _a;
    }

    void show()
    {
     std::cout<<"a 调用 b 的接口"<<std::endl;
    }
};

typedef std::shared_ptr<TestB> TestBPtr;

#endif

// main.cpp
#include "TestB.h"

int main ()
{
 TestBPtr b(new TestB());
 b->create_a();
 b->get_a()->set(b);
 b->get_a()->show();
}
max_min_ 2013-08-05
  • 打赏
  • 举报
回复
引用 13 楼 u011102675 的回复:
[quote=引用 12 楼 max_min_ 的回复:] [quote=引用 11 楼 u011102675 的回复:] [quote=引用 10 楼 max_min_ 的回复:] [quote=引用 9 楼 u011102675 的回复:] TestA.h

class TestB;
typedef boost::shared_ptr<TestB> TestBPtr;

class TestA
{

public:
	TestBPtr _b;

public:
	void set(TestBPtr B);

	void show();


};

typedef boost::shared_ptr<TestA> TestAPtr;
TestA.cpp

#include "TestA.h"
#include "TestB.h"

void TestA::set(TestBPtr B)
{
	_b = B;
}

void TestA::show()
{
	_b->show();
}
TestB.h

#include "TestA.h"

namespace logserver
{

class TestB
{
public:
	TestAPtr _a;

	void create_a()
	{
		TestAPtr p(new TestA());
		_a = p;
	}

	TestAPtr get_a()
	{
		return _a;
	}

	void show()
	{
		cout<<"a 调用 b 的接口"<<endl;
	}

};

typedef boost::shared_ptr<TestB> TestBPtr;
以下是使用 TestBPtr b(new TestB()); b->create_a(); b->get_a()->set(b); b->get_a()->show(); 是有内存泄漏的,已经测试过了
内存泄露是自己分配的堆空间没有及时释放而引起的 你这里唯一一处申请堆空间的就是 new一个testA对象而已, 你手动写一个析构函数出来释放掉,看看内存情况, 如果有内存泄露,之前定义也是有的! 不可能会是因为你前置定义引起导致内存泄露的, 我不晓得你是怎么测试的[/quote] 利用测试内存泄漏软件测试的[/quote] 不要默认的析构函数, 你自己也一个,要delete掉你new出来对象,再测试[/quote] 我两个类用的都是智能指针...[/quote] 这个和你两个累是不是智能指针真的没有关系的,内存泄露就是你没有及时释放你自己malloc或者new出来的空间而已,肯定不是前置申明导致内存泄露的,再好好查查别的部分代码吧
max_min_ 2013-08-04
  • 打赏
  • 举报
回复

// 申明
class TestA;
typedef boost::shared<TestA> TestAPtr;

u011102675 2013-08-04
  • 打赏
  • 举报
回复
引用 2 楼 qq120848369 的回复:
class XX;就可以了
我在这个类里用的不是 class TestA*,而是 TestAPtr p; 怎么申明了?
qq120848369 2013-08-04
  • 打赏
  • 举报
回复
class XX;就可以了
u011102675 2013-08-04
  • 打赏
  • 举报
回复
没办法只有自己顶了
申明一下,TPFanControl是原大神写的.因长期找不到绿色版,所以我只是绿化了一下.方便像我这种喜欢绿色软件的朋友. 人格担保: 绿色版完全从安装版绿化而来,决不添加任何流氓插件等. 解压缩后,可以放入任何文件夹内,然后运行!)Green.bat一下,完成绿化,如果怕的话,可以手动将TVicPort.sys拷入c:\windows\system32\drivers完成绿化 之后就可以双击TPFanControl.exe运行了,其中TPFanControl-0.62.exe是0.62版的,经MD5检查,0.62版和0.63版只有这一个文件有区别. ini配置文件是我自己重新定义的,大家可以自行修改,搜索MenuLabelSM1=Smart Mode 1,然后下面的温度自己调. 为了方便大家阅读,把配置的内容贴在下面了,配合浅显易懂的中文翻译,纯手工翻译!!非直译,其中(* *)中间的注释是我本人的注释,非翻译. // !!! Temp of lowest Level > 79 -> switch to Fahrenheit !!! see below // 最低一级的温度值如果>79的话,则温度自动识别为华氏度. // ATTENTION: example temp values are for my T61, especially //BluetoothEDR=1, SensorName5=no5, IgnoreSensors=no5 too // temp levels 10 degrees centgrade higher than in T4x, R5x, // change for your purposes. // 注意,下面的温度设置是以我的T61为例,特别是蓝牙EDR设置为1,第五个传感器名称改为no5,并且忽略这个传感器的温度显示.在T4X,R5X机器上,温度设置要高个10°,总之以你自己实测的效果来调试. // advice for programmers: TPFanControl must acquire mutex named // "Access_Thinkpad_EC" to get access to embedded controller // 建议: TPFanControl必须获得"Access_Thinkpad_EC"才能得到温度值. // with Active=3 & ManFanSpeed=0 & ManModeExit=78 you can have a nice // quiet time until temps reaches 78 deg. centigrade :-)) // 当使用手动模式(Active=3),风速为0(ManFanSpeed=0),并且将"手动切换到智能的温度阀值"设定为78°(ManModeExit=78)的话,你的电脑将会异常安静,除非温度攀升到78°. // ----------------------------------------------------------------- // ----------------------------------------------------------------- // "Active=0" program just reads config. 程序仅读取配置 // "Active=1" allow program to modify fan. 允许程序修改风速 // "Active=2" program will come up in smart mode. 程序以智能模式启动 // "Active=3" program will come up in manual mode. 程序以手动模式启动 Active=2 // ----------------------------------------------------------------- // manual fan speed at program start // 程序启动时,手动风速的初始值.(*我发现我的T61上,64风速是最快的*) ManFanSpeed=64 // ----------------------------------------------------------------- // Program exits manual mode and switches to smart mode with last chosen // profile, if this temp (degrees Centigrade or Fahrenheit) is achieved. // default= 80 degrees Centigrade / 176 degrees Fahrenheit. // 当温度达到该值时,程序将自动退出手动模式,并切换到之前启用过的智能模式. ManModeExit=78 //ManModeExit=172 // with Fahrenheit // ----------------------------------------------------------------- // Window stays on Top if StayOnTop=1, normal behavior =0 // 窗口是否一直前置显示,1为前置,默认为0,不前置. StayOnTop=0 // ----------------------------------------------------------------- // Set to 1 for slim widget // 1为窗口细长型显示,0为窗口粗矮型显示,显示的信息量相应的多一些. SlimDialog=1 // ----------------------------------------------------------------- // set to 1 for bluetooth with enhanced data rate (i.e. T61, // X61 for T4x, R5x set BluetoothEDR=0 ) // 设置为1时增强蓝牙的传输速率,例如T61,X61.但是对于T4x,R5x,请设置为0 BluetoothEDR=1 // ----------------------------------------------------------------- // Windows Priority of Process (0-5, normal=2), increase if fancontrol has // big delays in response while other processes consume performance. // 程序的优先级,可以设定为0-5,正常是2,如果其他程序大量消耗系统资源导致TPFanControl有较大的延迟,请把这个数值加大. ProcessPriority=5 // ----------------------------------------------------------------- // Show no icon ballons: NoBallons=1, show icon ballons: NoBallons=0 // 禁止托盘处的程序图标显示提示信息时,设为1,反之设为0. NoBallons=1 // ----------------------------------------------------------------- // check temperatures every x seconds (default 5) // 每隔x秒检查温度,默认是5. Cycle=1 // ----------------------------------------------------------------- // For Thinkpads A2x,T2x,X2x set NoExtSensor=1 to exclude reading // of extended sensors to prevent program errors. Attention 570(E) // is NOT compatible. Fan speed is not available on all models. // 对于Thinkpad A2x,T2x,X2x,设为1可以避免因读取不存在的温度传感器而导致程序出错.注意,570(E)是不兼容的.所有的机型上都无法设定风速. NoExtSensor=0 // ----------------------------------------------------------------- // Minimize to systray immediately when starting // 设定为1时,当程序启动后,立即最小化到托盘. StartMinimized=1 // ----------------------------------------------------------------- // check icon of tpfcicon.exe (optional) every x seconds (default 1) // 每x秒检查tpfcicon.exe的图标(可选,默认是1秒). IconCycle=1 // ----------------------------------------------------------------- // Show new icon with max. temperature / sensor name // 显示最高的温度和芯片的名称 ShowTempIcon=1 // ----------------------------------------------------------------- // Save the icon by a start delay of the program/service of // "SecStartDelay" (sec.) within "SecWinUptime" (sec.) after (re)boot // Delete slashes '//' at next 3 parameters. // 在启动或重启后,设定程序的延时启动时间,将下面的'//'删掉就能启用(*这个没啥用,我不弄的*) //SecWinUptime=120 //"SecWinUptime" (sec.) after (re)boot //SecStartDelay=60 //start delay of the program (sec.) //NoWaitMessage=0 //set to 1 to avoid sleep message //ReIcCycle=600 //rebuild TempIcon every xxx secs. // ----------------------------------------------------------------- // Temperature thresholds for turning the taskbar icon // yellow orange red (Smart and Manual mode only and // only together with MinimizeToTray=1) // 对于不同的温度,系统托盘所显示的颜色,黄,橙,红.仅在智能和手动模式下生效,并且MinimizeToTray=1 IconLevels=50 60 65 // Fahrenheit: IconLevels=122 140 158 // ----------------------------------------------------------------- // Beep frequency and duration (in ms) for successful // fan state changes. (Set either or both to zero to // disable) // 当成功转换风扇状态时,蜂鸣器的频率和时长(毫秒),任何一个值设定为0时,禁止蜂鸣. FanBeep=0 0 // -------------------------------------------------------- // If this max number of consecutive EC read errors occur // program will switch fan back to bios mode and exit // 当读取温度传感器的错误次数达到改设定值后,程序将自动切换到bios控制并退出. MaxReadErrors= 10 // -------------------------------------------------------- // Log2File=1 enables, Log2File=0 disables writing to TPFanControl.log // Start program with admin rights. // 允许或禁止写入日志文件,这个需要管理员权限 Log2File=0 // -------------------------------------------------------- // Log2csv=1 enables, Log2csv=0 disables // writing to TPFanControl_csv.txt renamed to // TPFanControl_last_csv.txt after restart of TPFanControl // rename to *.csv for use with excel // Start program with admin rights. // 设定为1时,允许日志写入TPFanControl_csv.txt,程序重启后,自动更名为TPFanControl_last_csv.txt.将扩展名改成.csv时,可以用excel打开.(*这个需要在文件夹选项中,将"隐藏已知类型的扩展名"后面的勾去掉才能显示并更改扩展名*) Log2csv=0 // -------------------------------------------------------- // List (separated by comma) of sensors to ignore when // determining the max. temperature. (Use lower case, // e.g "IgnoreSensors=pci,aps") // 判断最高温度时,哪些芯片是不受监控的(相当于黑名单,多个名称用逗号隔开,并用小写字母). IgnoreSensors=cpu,aps,crd,bat,bus,pci,pwr // (*我的T61有显卡门,所以只监控gpu的温度,除了gpu,其他所有的芯片都列上去了.大家可以把cpu从黑名单中删除*) // --------------------------------------------------------- // List of new 3 letter sensor names, delete leading // slashes to activate. Don't use capital letters for readability // of temp icon. // 写3个新的字母来重新命名芯片的名称,把'//'删除就能启用.别用大写字母 //SensorName1=cpu //SensorName2=aps //SensorName3=pcm //SensorName4=gpu //SensorName5=no5 //SensorName6=x7d //SensorName7=bat //SensorName8=x7f //SensorName9=bus //SensorName10=pci //SensorName11=pwr //SensorName12=xc3 // --------------------------------------------------------- // calculating Highest Temp with: // temperature of sensor no. = real temp minus SensorOffsetno. // Default SensorOffset1-12=0 , Capital O in SensorOffset, // to activate delete slashes '//', // Negative SensorOffsetno. values increase temperature values. // 重新计算最高温度,传感器温度=实测温度-偏移量,默认的偏移量都为0,删除'//'可以启用计算.当偏移量为负数时,则增大温度值 //SensorOffset1=20 //SensorOffset2=20 //SensorOffset3=0 //SensorOffset4=2 //SensorOffset5=1 //SensorOffset6=5 //SensorOffset7=5 //SensorOffset8=4 //SensorOffset9=3 //SensorOffset10=2 //SensorOffset11=1 //SensorOffset12=5 // ----------------------------------------------------------------- // set to 1 to show calculated temps for sensors // 设定为1时,显示计算后的温度值 ShowBiasedTemps=1 // ----------------------------------------------------------------- // Show all/active sensors at start up. all=1 only active=0 // 在启动时,显示所有/激活的传感器温度值,1为所有,0为激活的 ShowAll=0 // -------------------------------------------------------- // temperature levels 'Level=' with associated fan levels // (for the fan to come back, temperature must fall // down to previous level). There may be more or // less levels in this list. The first one should // have a fan speed of zero and is the "turn off" // temperature. // Fan speed of 64 is extreme and may be an *unsupported* // and *damaging* mode. A fan speed of 128 setting is // not really a fan speed in itself but will instead switch // fan control to BIOS mode (0x80). The idea of this // is to let the program get out of the way and let the // BIOS handle extremes.(and then switch back to smart if // the temperature is okay again) // Temp of lowest Level (commonly set to fan speed zero) of profile // "Smart Mode 1" will switch from Celsius to Fahrenheit if set higher // than 79 degrees. Temps of higher levels have no influence on F/C. // // profile "Smart Mode 1" // change values and number of items for your needs // Celsius: // Fahrenheit: MenuLabelSM1=Smart Mode 1/ Label for Icon Menu, must be terminated by '/' Level=30 0 // Level=140 0 Level=40 1 // Level=150 1 Level=45 4 // Level=165 3 Level=49 7 // Level=175 7 Level=52 64 // Level=195 64 // (*这些是我的温度设定,分别设定了30°,40°,45°,49°,52°,可以自己改*) // optional 2nd profile "Smart Mode 2", switched by icon menue // change values and number of items for your needs // to deactivate, insert leading '//' into following lines MenuLabelSM2=Smart Mode 2/ Label for Icon Menu, must be terminated by '/' // (*智能模式2下的设定*) Level2=30 0 // Level=140 0 Level2=40 1 // Level=150 1 Level2=45 4 // Level=165 3 Level2=49 7 // Level=175 7 Level2=52 64 // Level=195 64 // ----------------------------------------------------------------- // IconColorFan=1 digital Icon will turn green while fan is running. // 设定为1时,当风扇转的时候,图标为绿色 IconColorFan=1 // ----------------------------------------------------------------- // Lev64Norm=1 : Fan level 64 acts as normal level with hysteresis, // fan will run till next lower temp step is reached (no pulsing fan). // If set to zero fan level 64 acts as emergency level without hysteresis, // fan will run till level64 temp is reached again (pulsing fan can happen). // 设定为1时,最高风速有延迟效应,也就是说,当温度下降到最高档温度值以下时,风速仍旧为最高,直到继续下降到下一档温度时,才调低到下一档风速.如果设置为0,则一旦下降到最高档温度以下时,就立马降低到下一档风速,直到温度再次超过最高档温度值时再调高到最高风速. Lev64Norm=1

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧