-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemManager.h
111 lines (76 loc) · 2.6 KB
/
MemManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Created by sunshine on 18-7-20.
//
#ifndef INC_2018071603SHARE_MEM_ANALYSE_MEMLINKER_H
#define INC_2018071603SHARE_MEM_ANALYSE_MEMLINKER_H
#include <cstddef>
#include <vector>
#include "Struct.h"
class MemManager {
public:
MemManager();
~MemManager();
bool linkMem(const int &shmid);
void setShmOffset(size_t &offset);//设置查询的起始位置
void setOutputFilename(const std::string &filename);
void setStructList(std::vector<StructNode *> &structList);
void setPrintNode(); //设置打印节点,目前为全部打印
void setQueryConditionList(std::vector<QueryCondition *> &queryConditionList);
void setQueryConditionTotalNum(const int &count);
void setStructSize(const int &size);
bool findData(const bool &isFirst);
bool recycleMemory();
private:
//****************结构数据**************//
std::vector<StructNode *> structList;
std::vector<QueryCondition *> queryConditionList; //查询条件
std::vector<PrintNode> printNodeList;
int structSize;
std::string filename;
int queryConditionTotalNum;
//共享内存指针
void *shm;//共享内存基址
void *curShm;//当前指针
size_t offset; //设置偏移
size_t shmSize;
//*************data input**************//
//以下数据可以缩短,如intN_t(N=8,16,32,64)可用int64_t代替,使用时进行转换即可。
int iData;
char cData;
char *strData;
int8_t int8Data;
int16_t int16Data;
int32_t int32Data;
int64_t int64Data;
uint8_t uint8Data;
uint16_t uint16Data;
uint32_t uint32Data;
uint64_t uint64Data;
unsigned char ucData;
short siData;
float fData;
double dData;
//进程挂载上共享内存
bool attachMem(const int &shmid);
//进程离开共享内存
bool leaveMem();
//判断相等
bool isEqual(void *lh, void *rh, const int &dataType);
bool isEqual(void *lh, void *rh, const int &dataType, const int &size);
//offset偏移到下一个struct块
void nextStructBlock();
//检查是否内存上溢
bool isMemOverFlow();
//从头搜索
bool search(const bool &isFirst);
//打印数据
bool printData();
//todo 优化打印
//bool printDataV2();
bool printDataToFile();
bool printByType(void *loc, const int &type);
bool printByType(void *loc, const int &type, const int &size);
bool printByType(void *loc, const int &type, std::ofstream &outFile);
bool printByType(void *loc, const int &type, std::ofstream &outFile, const int &size);
};
#endif //INC_2018071603SHARE_MEM_ANALYSE_MEMLINKER_H