一个完整的吃内存程序

本文介绍了一个C#编写的程序,用于消耗计算机物理内存,以进行压力测试。程序包含一个简单的用户界面,允许用户指定要消耗的内存大小,并显示当前的内存使用情况。通过调用Windows API获取内存信息,此工具可用于测试系统的内存管理能力。
摘要由CSDN通过智能技术生成
一个完整的吃内存程序
作者:苏显斌
日期:2006年5月24日
这个程序是本人在公司测试自己编写的安装程序其间编写的一个小程序,主要目的是用来测试本机在不同剩余内存的情况下,安装程序执行的情况,现在把这个工具放上来给大家共享,希望有用得到的,同时也希望各位在阅读代码的过程中,发现有设计、编码等问题,不吝给予指出。
 
一、             界面设计
 
二、             界面部分的代码
/*
 * 名称:吃掉内存程序
 * 说明:用于吃掉物理内存的大小,以便可以进行软件的压力测试。
 * 作者:苏显斌
 * 创建日期:2006-03-02
 * 修改补充:
*/
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
 
namespace SetupMemoryTest
{
     ///<summary>
     /// Form1 的摘要说明。
     ///</summary>
     public class Form1 : System.Windows.Forms.Form
     {
         public delegate void ReleaseButtonHandler(bool isEnable);
         public delegate void ShowErrorMessageHandler(Exception ex);
 
         private bool isCancel = false;
         private ReleaseButtonHandler releaseButton;
         private ShowErrorMessageHandler showErrorMessage;
 
         private System.Windows.Forms.TextBox eatMemorySize;
         private System.Windows.Forms.Button excute;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.Label availableMemory;
         private System.Windows.Forms.Label totalMemory;
         private System.Windows.Forms.Label label4;
         private System.Windows.Forms.Timer timer1;
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.Button releaseMemory;
         private System.Windows.Forms.StatusBar statusBar1;
         private System.Windows.Forms.StatusBarPanel statusBarPanel1;
         private System.ComponentModel.IContainer components;
 
         public Form1()
         {
              //
              // Windows 窗体设计器支持所必需的
              //
              InitializeComponent();
 
              releaseButton = new ReleaseButtonHandler(this.SetReleaseButton);
              showErrorMessage = new ShowErrorMessageHandler(this.ShowErrorMessage);
         }
 
         ///<summary>
         /// 清理所有正在使用的资源。
         ///</summary>
         protected override void Dispose( bool disposing )
         {
              if( disposing )
              {
                   if (components != null)
                   {
                       components.Dispose();
                   }
              }
              base.Dispose( disposing );
         }
 
         #region Windows 窗体设计器生成的代码
         ///<summary>
         /// 设计器支持所需的方法 - 不要使用代码编辑器修改
         /// 此方法的内容。
         ///</summary>
         private void InitializeComponent()
         {
              this.components = new System.ComponentModel.Container();
              this.eatMemorySize = new System.Windows.Forms.TextBox();
              this.excute = new System.Windows.Forms.Button();
              this.label1 = new System.Windows.Forms.Label();
            
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值