TechTree(IT|Dev|SW)/C | C++ | VC++
[소스공개] 시세공유::공유메모리로 주식 시세,프로세스간 데이터 공유V2
DURUMUL
2025. 10. 2. 12:46
시세전광판 구현원리 공개
https://www.paypal.com/paypalme/duruedit
SHMSiseApp.7z
0.06MB
SHMSIse.zip
0.10MB
공유메모리로 주식 시세나 프로세스간 데이터 공유하는 방법
[version update] bugfix in 2025/10/01 as below
예제) 소스에서 추출(a part of source)
메모리데이타를 ui에 표시할때 for문 돌지말고 해당 즉시 binary_search 로 빨리표시(호가시세,체결시세등) 활용한다.
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
|
void CSiseWnd::RefreshSise()
{
GDCtrl* pGrid = &m_Grid[0];
SHMSISEITEM* pItem = NULL;
//SHMSISEITEM* pItemList[4800] = { 0, };
SHMSISEHEADER* pmapheader;
CString strtext, strline;
pmapheader = (LPSHMSISEHEADER)g_shmtool.m_siseconf.mapping;
if (!pmapheader)
return;
strtext.Format("[HEADER] mapsize=%ld,itemcount = %d writeindex=%04d uptime=%06d",
pmapheader->mapsize, g_shmtool.m_siseconf.nMaxItems,
pmapheader->lastwriteindex, pmapheader->lasttime);
AddLineString(strtext.GetBuffer(), 1);
int lines = 0;
int nItemSize = sizeof(SHMSISEITEM);
strtext = "";
m_Grid[0].SetRowCount(g_shmtool.m_siseconf.nMaxItems + 1);
#if 1
pGrid->SetRedrawNow(FALSE, FALSE);
pGrid->DeleteRows(1, -1);//해더제외한 나머지삭제
//pGrid->SetRedrawNow(TRUE, TRUE);
//pGrid->ResetScrollBars();
//pGrid->Invalidate();
#endif
int irow = 0;
//MYVECTOR_LONG m_veccindex
m_veccindex.clear();
//for (int ii = 0; ii < g_shmtool.m_siseconf.nMaxItems; ii++) {
for (int ii = 0; ii < pmapheader->realcount; ii++) {
//SHMSISEITEM item = { 0, };
//g_shmtool.GetSHMData(ii, &item);
////pItem = (SHMSISEITEM*)&pRootItem[ii];
////pItem->index = ii;
////pItemList[ii] = pItem;
//if (!item.si.shtcode[0])
// break;
LPSHMSISEITEM pItem = g_shmtool.GetSHMData(ii);
irow = AddToList(&m_Grid[0], pItem);// pItem);
m_veccindex.push_back(MYVECTOR_LONG::value_type(pItem->si.shtcode, irow));
}
int findrow = -1;
string scode = "000040";
findrow = GetCodeRowIndex(scode);
findrow = GetCodeRowIndex2(scode);
pGrid->SetRedrawNow(TRUE, TRUE);
pGrid->ResetScrollBars();
pGrid->Invalidate();
}
// Custom comparison function for lower_bound
//bool comparePairsByFirst(const std::pair<int, int>& p, int key) {
bool comparePairsByFirst(const pair<string, LONG>& p, string key) {
//bool comparePairsByFirst(const MYVECTOR_LONG& p, string key) {
return p.first >= key;
}
int CSiseWnd::GetCodeRowIndex(string scode)
{
long irow = -1;
// Find the lower bound using the custom comparator
auto it = std::lower_bound(m_veccindex.begin(), m_veccindex.end(), scode, comparePairsByFirst);
if (it != m_veccindex.end() && it->first == scode) {//found
int findex = std::distance(m_veccindex.begin(), it);
irow = it->second;
return irow;
}
return irow;
}
int CSiseWnd::my_lower_bound(MYVECTOR_LONG& index, string key, int begin, int end, int* recursive)
{
int findex = -1;
string s1, s2;
if (end >= index.size())
end = index.size() - 1;
if (begin > end) return -1;
int m = (begin + end) / 2;
s1 = index[m].first;
s2 = key;
if (s1 == s2) return m;
if (recursive) (*recursive)++;
if (s1 > s2)
findex = my_lower_bound(index, key, begin, m - 1, recursive);
else findex = my_lower_bound(index, key, m + 1, end, recursive);
return findex;
}
int CSiseWnd::GetCodeRowIndex2(string scode)
{
long irow = -1;
MYVECTOR_LONG::iterator it;
// Find the lower bound using the custom comparator
int recursive = 0;
int findex = my_lower_bound(m_veccindex, scode, 0, m_veccindex.size(), &recursive);
if (findex >= 0) {
it = m_veccindex.begin() + findex;
irow = it->second;
}
return irow;
}
|
cs |
https://www.paypal.com/paypalme/duruedit