📄 form1.h
字号:
#pragma once
#include "stdafx.h"
#define LINE_LEN 60
#define MAX_RECT_HEIGHT 100
#define MIN_RECT_WIDTH 30
#define MIN_RECT_HEIGHT 30
#define MAX_RECT_WIDTH 100
using namespace System::Drawing;
namespace memadim {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
_myGraphics = this->pictureBox1->CreateGraphics();
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Button^ Init_Memory;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::GroupBox^ groupBox1;
protected:
#pragma region 许晖冬自定的变量
public:
char *G_TestMem;
private:
int G_FontLineSpace;
int G_TestMemLen;
char **Test_sp; //用于保存分配出去的测试指针
int Test_sp_num; //已经分配的指数数目
int Test_Alloc_Mem; //已经分配出去的内存大小
int *Test_Space; //保存相应的分配出去的大小
int G_Width;
int G_Height;
int Org_X;
int Org_Y;
array<Rectangle, 1>^ _BusyItem; //忙链表中的表项数组
array<Point, 2>^ _BusyItemPoint; //忙链表中的表项的4个关键点next,prev, next, prev
array<String^, 2>^ _BusyItemInfo; //忙链表中的表项的关键信息
Pen^ _BusyPen; //忙链表使用Pen
SolidBrush^ _BusyBrush; //忙链表使用Bursh
System::Drawing::Font^ _BusyFont; //忙链表使用Font
int _BusyItemSum; //忙链表的总共块数
array<Rectangle, 1>^ _IdleItem; //空链表中的表项数组
array<Point, 2>^ _IdleItemPoint; //空链表中的表项的4个关键点next,prev, next, prev
array<String^, 2>^ _IdleItemInfo; //空链表中的表项的关键信息
Pen^ _IdlePen; //空链表使用Pen
SolidBrush^ _IdleBrush; //空链表使用Bursh
int _IdleItemSum; //空链表的总共块数
array<Rectangle, 1>^ _ErrItem; //链表中出错的表项数组
array<Point, 2>^ _ErrItemPoint; //链表中出错的表项的4个关键点next,prev, next, prev
array<String^, 2>^ _ErrItemInfo; //链表中出错的表项的关键信息
Pen^ _ErrPen; //链表出错表项使用Pen
SolidBrush^ _ErrBrush; //链表出错表项使用Bursh
int _ErrCount; //出错的个数
array<Rectangle, 1>^ _PhyItem; //物理链表中的表项数组
array<Point, 2>^ _PhyItemPoint; //物理链表中的表项的4个关键点next,prev, next, prev
array<String^, 2>^ _PhyItemInfo; //物理链表中的表项的关键信息
Pen^ _PhyPen; //物理链表中项使用Pen
SolidBrush^ _PhyBrush; //物理链表中项使用Bursh
int _PhyCount; //物理的个数
Graphics^ _myGraphics; //要使用的画布
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox3;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::CheckBox^ checkBox4;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox1;
#pragma endregion
/// <summary>
/// 画出Rect数组。
/// _DestRectArray 要画出的矩形数组的数目
/// _DestRectKeyPoint 矩形所对应的关键点的坐标
/// _DrawPen 要使用的画笔
/// _DrawBrush 填矩形框用的画刷
/// _RectNum 矩形的数目
/// </summary>
private: System::Void Sub_DrawList(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, Pen^ _DrawPen, SolidBrush^ _DrawBrush, array<String^, 2>^ _DrawInfo, System::Drawing::Font^ _DrawFont, int _RectNum)
{
int i;
_myGraphics->FillRectangles(_DrawBrush, _DestRectArray);
for(i = 1; i <= _RectNum - 1; i++)
{
if(_DestRectKeyPoint[i - 1, 0].Y == _DestRectKeyPoint[i, 0].Y)
{
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
else
{
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawPen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
}
for(i = 0; i < _RectNum; i++)
{
_myGraphics->DrawString(_DrawInfo[i, 0], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 1], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 7], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
}
///<summary>
///_DestRectArray 要计算的目标Rect
///_DestRectKeyPoint 要计算的目标Point
///Start_X 开始的X坐标
///Start_Y 开始的Y坐标
///Num Rect的数目
///</summary>
private:System::Void Sub_ComputerRectAndPoint(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, int Start_X, int Start_Y, int Num)
{
int i;
int j;
int rect_width, rect_height;
int x;
i = Num;
j = G_Width - LINE_LEN * (i - 1);
if((j / i) > MAX_RECT_WIDTH)
{
rect_width = MAX_RECT_WIDTH;
}
else if((j / i) < MIN_RECT_WIDTH)
{
rect_width = MIN_RECT_WIDTH;
}
else
{
rect_width = j / i;
}
rect_height = MIN_RECT_HEIGHT;
_DestRectArray[0].X = Org_X;
_DestRectArray[0].Y = Org_Y;
_DestRectArray[0].Width = rect_width;
_DestRectArray[0].Height = rect_height;
//可能要出现换行
if((rect_width * i) > (G_Width - LINE_LEN * (i - 1)))
{
//要换行
for(j = 1; j < i; j++)
{
if((_DestRectArray[j - 1].X + rect_width + LINE_LEN) > (G_Width - LINE_LEN))
{
_DestRectArray[j].X = Org_X;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y + _DestRectArray[j - 1].Height + G_FontLineSpace * 5 + 5; //加上5的分格
}
else
{
_DestRectArray[j].X = _DestRectArray[j - 1].X + rect_width + LINE_LEN;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y;
}
_DestRectArray[j].Width = rect_width;
_DestRectArray[j].Height = rect_height;
}
}
else
{
//要把矩形框平均地分布在平面内
j = G_Width - i * rect_width;
if(i == 1)
x = j;
else
x = j / (i - 1);
for(j = 1; j < i; j++)
{
_DestRectArray[j].X = _DestRectArray[j - 1].X + rect_width + x;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y;
_DestRectArray[j].Width = rect_width;
_DestRectArray[j].Height = rect_height;
}
}
for(j = 0; j < i; j++)
{
_DestRectKeyPoint[j,0].X = _DestRectArray[j].X;
_DestRectKeyPoint[j,0].Y = _DestRectArray[j].Y + 5;
_DestRectKeyPoint[j,1].X = _DestRectArray[j].X;
_DestRectKeyPoint[j,1].Y = _DestRectArray[j].Height + _DestRectArray[j].Y - 5;
_DestRectKeyPoint[j,2].X = _DestRectArray[j].X + _DestRectArray[j].Width;
_DestRectKeyPoint[j,2].Y = _DestRectArray[j].Y + 5;
_DestRectKeyPoint[j,3].X = _DestRectArray[j].X + _DestRectArray[j].Width;
_DestRectKeyPoint[j,3].Y = _DestRectArray[j].Height + _DestRectArray[j].Y - 5;
}
}
///<summary>
///画出物理内存块
/// _DestRectArray 要画出的矩形数组的数目
/// _DestRectKeyPoint 矩形所对应的关键点的坐标
/// _DrawBusyPen 用于画忙的Pen
/// _DrawBusyBrush 用于画忙的Brush
/// _DrawIdlePen 用于画空的Pen
/// _DrawIdleBrush 用于画空的Brush
/// _DrawInfo 要显示的信息
/// _DrawFont 用于显示信息的Font
/// _RectNum 矩形的数目
///</summary>
private:virtual System::Void Sub_DrawPhyListItem(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, Pen^ _DrawBusyPen, SolidBrush^ _DrawBusyBrush, Pen^ _DrawIdlePen, SolidBrush^ _DrawIdleBrush, array<String^, 2>^ _DrawInfo, System::Drawing::Font^ _DrawFont, int _RectNum)
{
int i;
UInt32 x1, AllSpace;
array<Char>^ xu_str = gcnew array<Char>(256);
String^ temp_str;
AllSpace = 0;
for(i = 0; i < _RectNum; i++)
{
xu_str->Clear(xu_str, 0, xu_str->GetLength(0));
_DrawInfo[i, 3]->CopyTo(5, xu_str, 0, _DrawInfo[i, 3]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::UInt32::Parse(temp_str, System::Globalization::NumberStyles::Integer);
AllSpace += x1;
xu_str->Clear(xu_str, 0, xu_str->GetLength(0));
_DrawInfo[i, 7]->CopyTo(5, xu_str, 0, _DrawInfo[i, 7]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::UInt32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 == 0xaa)
{
_myGraphics->FillRectangle(_DrawBusyBrush, _DestRectArray[i]);
_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
else
{
_myGraphics->FillRectangle(_DrawIdleBrush, _DestRectArray[i]);
_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 3], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
if((i != 0) )//&& (i != (_RectNum - 1)))
{
if(_DestRectKeyPoint[i - 1, 0].Y == _DestRectKeyPoint[i, 0].Y)
{
if(x1 == 0xaa)
{
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
else
{
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
}
else
{
if(x1 == 0xaa)
{
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawBusyPen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
else
{
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawIdlePen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
}
}
}
_myGraphics->DrawString("总共内存大小:" + AllSpace.ToString(), _DrawFont, _DrawBusyBrush, 50, _DestRectArray[_RectNum - 1].Y + _DestRectArray[_RectNum - 1].Height + 100);
}
///<summary>
///_AnalyseInfo 要分析的链表的相关信息
///_Num 表项的个数
///_AnalyseErr 出错的矩形框
///_AnalyseErrInfo 出错的表项的信息
///_AnalyseItemPoint 出错表项的关键点
///</summary>
private:System::UInt32 Fun_AnalyseList(array<String^, 2>^ _AnalyseInfo, int Num, array<Rectangle, 1>^ _AnalyseErr, array<String^, 2>^ _AnalyseErrInfo, array<Point, 2>^ _AnalyseItemPoint)
{
int count;
unsigned int x1, x2, j;
int *errarray;
count = 0;
array<Char>^ xu_str = gcnew array<Char>(256);
String^ temp_str;
errarray = new int [Num];
for(j = 1; j < Num; j++)
{
_AnalyseInfo[j - 1, 0]->CopyTo(5, xu_str, 0, _AnalyseInfo[j - 1, 0]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
_AnalyseInfo[j, 6]->CopyTo(5, xu_str, 0, _AnalyseInfo[j, 6]->Length - 5);
temp_str = gcnew String(xu_str);
x2 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 != x2)
{
errarray[j] = 1;
count += 1;
}
else
{
_AnalyseInfo[j, 1]->CopyTo(5, xu_str, 0, _AnalyseInfo[j, 1]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
_AnalyseInfo[j - 1, 6]->CopyTo(5, xu_str, 0, _AnalyseInfo[j - 1, 6]->Length - 5);
temp_str = gcnew String(xu_str);
x2 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 != x2)
{
errarray[j] = 1;
count += 1;
}
else
{
errarray[j] = 0;
}
}
}
if(count == 0)
{
return count;
}
_AnalyseErr = gcnew array<Rectangle, 1>(count);
_AnalyseErrInfo = gcnew array<String^, 2>(count, 7);
_AnalyseItemPoint = gcnew array<Point, 2>(count, 4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -