⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localheapmm.pas

📁 delphi开发语言下的源代码分析
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          ListView_InsertColumn(hRegionView, 0,column);
          column.cx:=70;
          column.pszText:='Addr';
          ListView_InsertColumn(hRegionView, 1,column);
          column.cx:=70;
          column.pszText:='Size';
          ListView_InsertColumn(hRegionView, 2,column);
          column.pszText:='Overhead';
          ListView_InsertColumn(hRegionView, 3,column);
          column.pszText:='Occupied';
          ListView_InsertColumn(hRegionView, 4,column);

          column.pszText:='Committed';
          ListView_InsertColumn(hRegionView, 5,column);
          column.pszText:='Uncommitted';
          ListView_InsertColumn(hRegionView, 6,column);

          SetWindowLong(hWnd, GWL_USERDATA,bShowDetails);
          result:=1;
        end;

        if (uMessage = WM_COMMAND) and (wParam = IDC_DETAILS)  then
        Begin
          bShowDetails := GetWindowLong(hWnd, GWL_USERDATA);
          if (bShowDetails = 0) then
          Begin
                SetWindowPos(hWnd,HWND_TOPMOST,0,0,632,505,SWP_NOMOVE + SWP_SHOWWINDOW);
                bShowDetails:=1;
                SetWindowLong( hWnd, GWL_USERDATA,bShowDetails);
                SendMessage(hWnd,WM_DUMP,0,0);
          end
          else
          Begin
                SetWindowPos(hWnd,HWND_TOPMOST,0,0,632,160,SWP_NOMOVE + SWP_SHOWWINDOW);

                bShowDetails:=0;
                hListView:=GetDlgItem(hWnd, IDC_DETAILS_LIST);
                ListView_DeleteAllItems(hListView);
                SetWindowLong( hWnd, GWL_USERDATA,bShowDetails);
          End;
         result:=1;
        End;
        if (uMessage =  WM_DUMP) then
        Begin
            bShowDetails := GetWindowLong( hWnd, GWL_USERDATA);

            SetDlgItemInt(hWnd,  IDC_MEM_OPS, HeapStats.iOperations,false);
            SetDlgItemInt(hWnd,  IDC_MEM_ALLOCATIONS, HeapStats.iTotalAllocations,false);
            SetDlgItemInt(hWnd,  IDC_MEM_FREES, HeapStats.iTotalFrees,false);
            SetDlgItemInt(hWnd,  IDC_MEM_OPENALLOCATIONS, HeapStats.iOpenAllocations,false);
            SetDlgItemInt(hWnd,  IDC_MEM_INUSE, HeapStats.iMemAllocated,false);
            if wparam <> 0 then
            Begin
              hTraceView:=GetDlgItem(hWnd, IDC_TRACE_LIST);
              ZeroMemory(@item,sizeof(TLVItem));
              item.mask := LVIF_TEXT;
              item.iItem:=0;
              item.iSubItem:=0;
              ZeroMemory(@localString,255);
              localString:='';
              Str(HeapStats.iOperations, localString);
              item.pszText:=pchar(Integer(Pointer(@localString))+1);
              ListView_InsertItem(hTraceView,item);

              item.iSubItem:=1;
              case wparam of
                 0 : item.pszText:='Dump';
                 1 : item.pszText:='GetMem';
                 2 : item.pszText:='FreeMem';
                 3 : item.pszText:='ReallocMem';
                 4 : item.pszText:='Compact Heap';
              End;
              ListView_SetItem(hTraceView,item);

              item.iSubItem:=2;
              ZeroMemory(@localString,255);
              Str(lParam, localString);
              item.pszText:=pchar(Integer(Pointer(@localString))+1);
              ListView_SetItem(hTraceView,item);

              item.iSubItem:=3;
              ZeroMemory(@localString,255);
              Str(HeapStats.iMemAllocated, localString);
              item.pszText:=pchar(Integer(Pointer(@localString))+1);
              ListView_SetItem(hTraceView,item);
              while (ListView_GetItemCount(hTraceView) > 500) do
              Begin
                ListView_DeleteItem(hTraceView,500);
              End;

            end;

            // extended stats?
            if (bShowDetails <> 0) AND (hHeap <> 0) then
            Begin

             hListView:=GetDlgItem(hWnd, IDC_DETAILS_LIST);
             hRegionView:=GetDlgItem(hWnd, IDC_DETAILS_REGION);

             ListView_DeleteAllItems(hListView);
             ListView_DeleteAllItems(hRegionView);
             if (HeapLock(hHeap)) then
             Try
                // WALK THE REGIONS
                ZeroMemory(@heapEntry,sizeof(TProcessHeapEntry));
                ZeroMemory(@item,sizeof(TLVItem));
                item.mask := LVIF_TEXT;
                item.iItem:=0;
                heapEntry.lpData:=nil;
                heapEntry.wFlags:= PROCESS_HEAP_REGION;
                while (HeapWalk(hHeap,heapEntry)  ) do
                Begin
                 // only show regions
                  if ( (heapEntry.wFlags OR PROCESS_HEAP_REGION) = heapEntry.wFlags ) then
                   begin
                    // use old mmanager.... avoid recursion...
                    item.iSubItem:=0;
                    ZeroMemory(@localString,255);
                    localString:='';
                    Str(heapEntry.iRegionIndex, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_InsertItem(hRegionView,item);

                    item.iSubItem:=1;
                    ZeroMemory(@localString,255);
                    Str(Integer(heapEntry.lpData),localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);

                    item.iSubItem:=2;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.dwCommittedSize + heapEntry.dwUncommittedSize,localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);

                    item.iSubItem:=3;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.cbOverhead, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);

                    item.iSubItem:=4;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.cbData+heapEntry.cbOverhead, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);

                    item.iSubItem:=5;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.dwCommittedSize, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);

                    item.iSubItem:=6;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.dwUnCommittedSize, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hRegionView,item);


                    Inc(item.iItem);
                   end;
                End;

             // NOW WALK THE ITEMS
                ZeroMemory(@heapEntry,sizeof(TProcessHeapEntry));
                ZeroMemory(@item,sizeof(TLVItem));
                item.mask := LVIF_TEXT;
                item.iItem:=0;
                heapEntry.lpData:=nil;
                heapEntry.wFlags:= PROCESS_HEAP_ENTRY_BUSY;
                while (HeapWalk(hHeap,heapEntry)  ) do
                Begin
                 // only show USED memory blocks
                  if ( (heapEntry.wFlags OR PROCESS_HEAP_ENTRY_BUSY) = heapEntry.wFlags ) then
                   begin
                    // use old mmanager.... avoid recursion...
                    item.iSubItem:=0;
                    ZeroMemory(@localString,255);
                    localString:='';
                    Str(heapEntry.iRegionIndex, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_InsertItem(hListView,item);

                    item.iSubItem:=1;
                    ZeroMemory(@localString,255);
                    Str(Integer(heapEntry.lpData),localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hListView,item);

                    item.iSubItem:=2;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.cbData,localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hListView,item);

                    item.iSubItem:=3;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.cbOverhead, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hListView,item);

                    item.iSubItem:=4;
                    ZeroMemory(@localString,255);
                    Str(heapEntry.cbData+heapEntry.cbOverhead, localString);
                    item.pszText:=pchar(Integer(Pointer(@localString))+1);
                    ListView_SetItem(hListView,item);

                    item.iSubItem:=5;
                    ZeroMemory(@localString,255);
                    i:=0;
                    item.pszText:=nil;

{                    if (heapEntry.cbData >= 4) then
                            getObjectData(heapEntry.lpData);
 }
                    if ( item.pszText=nil) then
                    BEgin
                      while ( (i < 255) AND (i < heapEntry.cbData))  do
                      Begin
                            c:=PChar(Cardinal(heapEntry.lpData)+i)^;
                            if (Ord(c) = 0) then
                                    c:='

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -