内存泄漏检测优化全局变量避免误报(continue)

This commit is contained in:
fasiondog 2020-04-05 18:18:32 +08:00
parent c76edbf4e9
commit 59bdac33df
7 changed files with 55 additions and 53 deletions

View File

@ -44,7 +44,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true

View File

@ -39,10 +39,11 @@ void GlobalInitializer::init() {
}
void GlobalInitializer::clean() {
DataDriverFactory::release();
StockManager::quit();
H5close();
DataDriverFactory::release();
//H5close();
spdlog::drop_all();

View File

@ -13,7 +13,6 @@
#include "kdata/hdf5/H5KDataDriver.h"
#include "kdata/mysql/MySQLKDataDriver.h"
#include "kdata/tdx/TdxKDataDriver.h"
#include "kdata/hdf5/H5KDataDriver.h"
#include "DataDriverFactory.h"
#include "KDataDriver.h"
@ -131,6 +130,15 @@ void DataDriverFactory::removeKDataDriver(const string& name) {
KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) {
KDataDriverPtr result;
string name = params.get<string>("type");
to_upper(name);
auto iter = m_kdataDrivers->find(name);
if (iter != m_kdataDrivers->end()) {
result = iter->second;
result->init(params);
}
return result;
/*KDataDriverPtr result;
auto param_iter = m_param_kdataDrivers->find(params);
if (param_iter != m_param_kdataDrivers->end()) {
result = param_iter->second;
@ -152,7 +160,7 @@ KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) {
(*m_param_kdataDrivers)[params] = result;
}
return result;
return result;*/
}
} /* namespace hku */

View File

@ -25,9 +25,9 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KDataDriverPtr& driver)
return os;
}
KDataDriver::KDataDriver() : m_name("") {}
KDataDriver::KDataDriver() : m_name(""), m_inited(false) {}
KDataDriver::KDataDriver(const string& name) : m_name(name) {
KDataDriver::KDataDriver(const string& name) : m_name(name), m_inited(false) {
to_upper(m_name);
}
@ -52,6 +52,10 @@ bool KDataDriver::checkType() {
}
bool KDataDriver::init(const Parameter& params) {
if (m_inited) {
return m_inited;
}
if (m_params == params) {
return true;
}
@ -61,34 +65,32 @@ bool KDataDriver::init(const Parameter& params) {
return false;
}
return _init();
m_inited = _init();
return m_inited;
}
void KDataDriver::loadKData(const string& market, const string& code, KQuery::KType kType,
size_t start_ix, size_t end_ix, KRecordListPtr out_buffer) {}
void KDataDriver::loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix,
size_t end_ix, KRecordListPtr out_buffer) {}
size_t KDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) {
return 0;
}
bool KDataDriver::getIndexRangeByDate(const string& market, const string& code, const KQuery& query,
size_t& out_start, size_t& out_end) {
bool KDataDriver::getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start,
size_t& out_end) {
return false;
}
KRecord KDataDriver::getKRecord(const string& market, const string& code, size_t pos,
KQuery::KType kType) {
KRecord KDataDriver::getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType) {
return Null<KRecord>();
}
TimeLineList KDataDriver ::getTimeLineList(const string& market, const string& code,
const KQuery& query) {
TimeLineList KDataDriver ::getTimeLineList(const string& market, const string& code, const KQuery& query) {
HKU_INFO("This driver not support time-line!");
return TimeLineList();
}
TransList KDataDriver ::getTransList(const string& market, const string& code,
const KQuery& query) {
TransList KDataDriver ::getTransList(const string& market, const string& code, const KQuery& query) {
HKU_INFO("This driver not support transaction record!");
return TransList();
}

View File

@ -48,8 +48,8 @@ public:
* @param end_ix
* @param out_buffer [out]
*/
virtual void loadKData(const string& market, const string& code, KQuery::KType kType,
size_t start_ix, size_t end_ix, KRecordListPtr out_buffer);
virtual void loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix,
size_t end_ix, KRecordListPtr out_buffer);
/**
* K线数据量
@ -69,8 +69,8 @@ public:
* @param out_end [out] K线记录位置
* @return
*/
virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query,
size_t& out_start, size_t& out_end);
virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start,
size_t& out_end);
/**
* K线记录
@ -80,8 +80,7 @@ public:
* @param kType K线类型
* @return
*/
virtual KRecord getKRecord(const string& market, const string& code, size_t pos,
KQuery::KType kType);
virtual KRecord getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType);
/**
* 线
@ -90,8 +89,7 @@ public:
* @param query
* @return
*/
virtual TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query);
virtual TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query);
/**
*
@ -107,6 +105,7 @@ private:
private:
string m_name;
bool m_inited; //是否已初始化
};
typedef shared_ptr<KDataDriver> KDataDriverPtr;

View File

@ -20,17 +20,14 @@ public:
virtual ~H5KDataDriver();
virtual bool _init() override;
virtual void loadKData(const string& market, const string& code, KQuery::KType kType,
size_t start_ix, size_t end_ix, KRecordListPtr out_buffer) override;
virtual void loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix,
size_t end_ix, KRecordListPtr out_buffer) override;
virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override;
virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query,
size_t& out_start, size_t& out_end) override;
virtual KRecord getKRecord(const string& market, const string& code, size_t pos,
KQuery::KType kType) override;
virtual TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query) override;
virtual TransList getTransList(const string& market, const string& code,
const KQuery& query) override;
virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start,
size_t& out_end) override;
virtual KRecord getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType) override;
virtual TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query) override;
virtual TransList getTransList(const string& market, const string& code, const KQuery& query) override;
private:
void H5ReadRecords(H5::DataSet&, hsize_t, hsize_t, void*);
@ -38,36 +35,31 @@ private:
void H5ReadTimeLineRecords(H5::DataSet&, hsize_t, hsize_t, void*);
void H5ReadTransRecords(H5::DataSet&, hsize_t, hsize_t, void*);
bool _getH5FileAndGroup(const string& market, const string& code, KQuery::KType kType,
H5FilePtr& out_file, H5::Group& out_group);
bool _getH5FileAndGroup(const string& market, const string& code, KQuery::KType kType, H5FilePtr& out_file,
H5::Group& out_group);
KRecord _getBaseRecord(const string&, const string&, size_t, KQuery::KType);
KRecord _getOtherRecord(const string&, const string&, size_t, KQuery::KType);
void _loadBaseData(const string& market, const string& code, KQuery::KType kType,
size_t start_ix, size_t end_ix, KRecordListPtr out_buffer);
void _loadIndexData(const string& market, const string& code, KQuery::KType kType,
size_t start_ix, size_t end_ix, KRecordListPtr out_buffer);
void _loadBaseData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, size_t end_ix,
KRecordListPtr out_buffer);
void _loadIndexData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, size_t end_ix,
KRecordListPtr out_buffer);
bool _getBaseIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start,
size_t& out_end);
bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start,
size_t& out_end);
bool _getBaseIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, size_t& out_end);
bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, size_t& out_end);
TimeLineList _getTimeLine(const string& market, const string& code, int64 start, int64 end);
TimeLineList _getTimeLine(const string& market, const string& code, const Datetime& start,
const Datetime& end);
TimeLineList _getTimeLine(const string& market, const string& code, const Datetime& start, const Datetime& end);
TransList _getTransList(const string& market, const string& code, int64 start, int64 end);
TransList _getTransList(const string& market, const string& code, const Datetime& start,
const Datetime& end);
TransList _getTransList(const string& market, const string& code, const Datetime& start, const Datetime& end);
private:
H5::CompType m_h5DataType;
H5::CompType m_h5IndexType;
H5::CompType m_h5TimeLineType;
H5::CompType m_h5TransType;
H5FilePtr m_h5file;
map<string, H5FilePtr> m_h5file_map; // key: market+code
};

View File

@ -87,8 +87,8 @@ target("small-test")
end
-- add files
--add_files("./hikyuu/hikyuu/**.cpp");
add_files("./hikyuu/hikyuu/test_StockManager.cpp");
add_files("./hikyuu/hikyuu/**.cpp");
-- add_files("./hikyuu/hikyuu/test_StockManager.cpp");
add_files("./hikyuu/test_main.cpp")
target_end()