VC 高手请指教如何把一个1G左右的文件读入内存并显示在CListCtrl控件中

flyingzerg 2006-10-23 09:54:50
如何把一个1G左右的文件读入内存并显示在CListCtrl控件中,我已经采用了内存映射文件但是,如果一次映射了28M,显示就会很慢了,共有记录28*1024*1024/25条(我的一个结构的大小时25),这么多的记录调用CListCtrl的redraw显示会很慢(没有读一条刷新的原因是那样会更慢).我认为问题的瓶颈是大数据量CListCtrl的显示问题,各位高手有没有好的办法解决.
...全文
392 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
pzhuyy 2006-10-23
  • 打赏
  • 举报
回复
全读进内存不科学也不可行..
烨炜带火 2006-10-23
  • 打赏
  • 举报
回复
对只能显示多少读多少!
alfwolf 2006-10-23
  • 打赏
  • 举报
回复
是的,在codeguru中也有virtual listctrl的例子,对于你的数据量来说,快速显示也基本上可以的.但是依然建议采用动态显示的方式,你的文件可能也需要做一些优化,比如记录的数量等.
dychenyi 2006-10-23
  • 打赏
  • 举报
回复
学习
cuiningsb 2006-10-23
  • 打赏
  • 举报
回复
使用虚模式啊
DATAGRID支持
pSK_LB 2006-10-23
  • 打赏
  • 举报
回复
UP
周江涛 2006-10-23
  • 打赏
  • 举报
回复
"ÿÌì");引号里是几个中文汉字,如"第年"等。拷在这变乱码了。
显示文件数据时,相应挪动文件指针就可以了。
周江涛 2006-10-23
  • 打赏
  • 举报
回复
在把listctrl的属性owner_data勾上,然后在OnGetdispinfoListTask()里写代码,我这里有个海量数据处理的项目源码,处理几千万行吧。显示多少读多少。

void CSetISTimer::OnGetdispinfoListTask(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem= &(pDispInfo)->item;

int nItemIndex= pItem->iItem;

CISTimerInfo *pISInfo = GetItemInfoByIndex(nItemIndex);
if (pISInfo == NULL)
return;

if(pItem->mask & LVIF_TEXT)
{
switch (pItem->iSubItem) //first column
{
case 0:
itoa(pISInfo->nCameraID, pItem->pszText, 10);
break;

case 1:
if (1 == pISInfo->nCameraType)
strcpy(pItem->pszText, "ÿÌì");
else if (2 == pISInfo->nCameraType)
strcpy(pItem->pszText, "ÿÖÜ");
else if (3 == pISInfo->nCameraType)
strcpy(pItem->pszText, "ÿÔÂ");
else if (4 == pISInfo->nCameraType)
strcpy(pItem->pszText, "Ò»´Î");
break;

case 2:
strcpy(pItem->pszText, pISInfo->strStartTime);
break;

case 3:
strcpy(pItem->pszText, pISInfo->strEndTime);
break;

case 4:
itoa(pISInfo->nRecSpan, pItem->pszText, 10);
break;

case 5:
itoa(pISInfo->nDay, pItem->pszText, 10);
break;

case 6:
itoa(pISInfo->nMonth, pItem->pszText, 10);
break;

case 7:
strcpy(pItem->pszText, pISInfo->strSavePath);
break;

case 8:
itoa(pISInfo->nDvrType, pItem->pszText, 10);
break;

case 9:
itoa(pISInfo->nUserInNode, pItem->pszText, 10);
break;

case 10:
itoa(pISInfo->nRule, pItem->pszText, 10);
break;

case 11:
strcpy(pItem->pszText, pISInfo->strUserName);
break;
}
}
*pResult = 0;
}

东文-桑晨 2006-10-23
  • 打赏
  • 举报
回复
显示多少就读多少
rickerliang 2006-10-23
  • 打赏
  • 举报
回复
学习了
rain4609 2006-10-23
  • 打赏
  • 举报
回复
1G......晕~你见过有把1G读入内存的程序吗?
都是分块处理的
DentistryDoctor 2006-10-23
  • 打赏
  • 举报
回复
应该用Virtual List Controls, 在MSDN中有相关的内容

其实真正需要显示的内容并不多,只读取需要显示的部分就行了。


A virtual list control is a list view control that has the LVS_OWNERDATA style. This style enables the control to support an item count up to a DWORD (the default item count only extends to an int). However, the biggest advantage provided by this style is the ability to only have a subset of data items in memory at any one time. This allows the virtual list view control to lend itself for use with large databases of information, where specific methods of accessing data are already in place.

Note
In addition to providing virtual list functionality in CListCtrl, MFC also provides the same functionality in the CListView class.


There are some compatibility issues you should be aware of when developing virtual list controls. For more information, see the Compatibility Issues section of the List-View Controls topic in the Platform SDK.

Handling the LVN_GETDISPINFO Notification
Virtual list controls maintain very little item information. Except for the item selection and focus information, all item information is managed by the owner of the control. Information is requested by the framework via a LVN_GETDISPINFO notification message. To provide the requested information, the owner of the virtual list control (or the control itself) must handle this notification. This can easily be done using the Properties window (see Mapping Messages to Functions). The resultant code should look something like the following example (where CMyListCtrl is the virtual list control object and the control is handling the notification):

Copy Code
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
END_MESSAGE_MAP()


In the handler for the LVN_GETDISPINFO notification message, you must check to see what type of information is being requested. The possible values are:

LVIF_TEXT The pszText member must be filled in.

LVIF_IMAGE The iImage member must be filled in.

LVIF_INDENT The iIndent member must be filled in.

LVIF_PARAM The lParam member must be filled in.

LVIF_STATE The state member must be filled in.

You should then supply whatever information is requested back to the framework.

The following example (taken from the body of the notification handler for the list control object) demonstrates one possible method by supplying information for the text buffers and image of an item:

Copy Code
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem= &(pDispInfo)->item;

int iItemIndx= pItem->iItem;

if (pItem->mask & LVIF_TEXT) //valid text buffer?
{
switch(pItem->iSubItem){
case 0: //fill in main text
lstrcpy(pItem->pszText,
m_Items[iItemIndx].m_strItemText);
break;
case 1: //fill in sub item 1 text
lstrcpy(pItem->pszText,
m_Items[iItemIndx].m_strSubItem1Text);
break;
case 2: //fill in sub item 2 text
lstrcpy(pItem->pszText,
m_Items[iItemIndx].m_strSubItem2Text);
break;
}
}

if pItem->mask & LVIF_IMAGE) //valid image?
pItem->iImage=
m_Items[iItemIndx].m_iImageIndex;


Caching and Virtual List Controls
Because this type of list control is intended for large data sets, it is recommended that you cache requested item data to improve retrieval performance. The framework provides a cache-hinting mechanism to assist in optimizing the cache by sending an LVN_ODCACHEHINT notification message. However, you must use a slightly different method to handle this notification. Using the Properties window, override the OnChildNotify function of your list control object. In the case of this example, CMyListCtrl.

Inside the body of the handler, check for the LVN_ODCACHEHINT message and, if found, prepare your cache.

The following example (taken from the body of the OnChildNotify function) performs this check and calls the PrepCache member function of the CMyListCtrl class.

Copy Code
NMLVCACHEHINT* pcachehint=NULL;

if (message == WM_NOTIFY)
{
NMHDR* phdr = (NMHDR*)lParam;

switch(phdr->code)
{
case LVN_ODCACHEHINT:
pcachehint= (NMLVCACHEHINT*) phdr;
// Load the cache with the recommended range.
PrepCache(pcachehint->iFrom, pcachehint->iTo);
break;
default:
return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
}
return FALSE;
}
else
return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);


Notice that the notification is passed on to the base class (CListCtrl) if the message type is not LVN_ODCACHEHINT. For more information on preparing and maintaining a cache, see the Cache Management section of the List-View Controls topic in the Platform SDK.

Finding Specific Items
The LVN_ODFINDITEM notification message is sent by the virtual list control when a particular list control item needs to be found. The notification message is sent when the list view control receives quick key access or when it receives an LVM_FINDITEM message. Search information is sent in the form of an LVFINDINFO structure, which is a member of the NMLVFINDITEM structure. Handle this message by overriding the OnChildNotify function of your list control object and inside the body of the handler, check for the LVN_ODFINDITEM message. If found, perform the appropriate action.

You should be prepared to search for an item that matches the information given by the list view control. You should return the index of the item if successful, or -1 if no matching item is found.


beijingshizi 2006-10-23
  • 打赏
  • 举报
回复
你见过谁一次显示那么多啊。

一次不用填充那么多数据,可以用next页之类的方法。

滚动的时候,你重新填充数据。分个十次八次的,不就行了?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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