items属性的combo_【内存消耗问题】DataGridViewComboboxColoumn关于Items属性和DataSource属性的性能开销问题...

news/2024/7/7 18:54:38

【问题场景】:新建窗体应用程序,Form中添加1个DataGridView控件,并新增1列数据(列类型为DataGridViewComboboxColoumn)。下拉列表绑定15000条选项值,表格添加15000行数据行。

【问题对比】:分别使用Items属性和DataSource属性绑定下拉列表数据,打开Windows任务管理器,观察内存消耗。

【测试结果】:(1)情况一:使用DataSource绑定数据,内存开销很小,且速度快,当CtrlC操作时,GetClipboardContent()消耗内存快速增加许多;情况二:使用Items绑定数据,内存开销较大,且速度慢,当CtrlC操作时,GetClipboardContent()消耗内存变化不大

(2)两种情况下,内存消耗的最大值借相差不大

【!!!问题!!!】:内存开销花在什么地方了?如何保持用DataSource绑定数据的小开销和快速,又能避免GetClipboardContent()操作内存消耗过大?

【示例代码】:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace TestComboBoxClipBoard

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown);

}

void dataGridView1_KeyDown(object sender, KeyEventArgs e)

{

if (e.Control && e.KeyCode == Keys.C)

{

//打断点,观察GetClipboardContent语句执行时,内存消耗情况

DataObject data = dataGridView1.GetClipboardContent();

}

}

private void button1_Click(object sender, EventArgs e)

{

List rowList = new List();

List items = new List();

int itemsCount = 15000;

for (int index = 0; index < itemsCount; index++)

{

items.Add(index.ToString());

}

//DataSource和Items的区别

//使用DataSource【新建表内存消耗不大,CtrlC操作后观察可知内存消耗变大】

(dataGridView1.Columns[0] as DataGridViewComboBoxColumn).DataSource = items.ToArray();

//使用Items【新建表内存消耗大,CtrlC操作后内存变化不大】

//(dataGridView1.Columns[0] as DataGridViewComboBoxColumn).Items.AddRange(items.ToArray());

for (int index = 0; index < itemsCount; index++)

{

DataGridViewRow row = new DataGridViewRow();

object[] para = { "123" };

row.CreateCells(dataGridView1, para);

rowList.Add(row);

}

dataGridView1.Rows.AddRange(rowList.ToArray());

}

}

}


http://lihuaxi.xjx100.cn/news/271975.html

相关文章

pythonexcel介绍_Python 中pandas.read_excel详细介绍

Python 中pandas.read_excel详细介绍 #coding:utf-8 import pandas as pd import numpy as np filefullpath r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/1.xls" #filefullpath r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/26368…

清华学霸组团的工业AIoT创企再获数千万融资:玩家应推动在边缘 AI 芯片上跑算法...

记者 | 夕颜采访嘉宾 | 马君&#xff0c;湃方科技联合创始人&总裁来源 | CSDN&#xff08;ID:CSDNnews&#xff09; 「AI技术生态论」 人物访谈栏目是CSDN发起的百万人学AI倡议下的重要组成部分。通过对AI生态顶级大咖、创业者、行业KOL的访谈&#xff0c;反映其对于行业的…

图像分类和目标检测技术有什么区别?

点击上方“小白学视觉”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达图像分类和目标检测技术是计算机视觉领域的重要研究方法。这些技术帮助机器理解和识别实时对象和环境&#xff0c;帮助数字图像作为输入。多年来&#xff0c;计算机视觉技…

再见,ACL!

点击上方“视学算法”&#xff0c;选择加"星标"或“置顶”重磅干货&#xff0c;第一时间送达作者&#xff1a;阿广公众号&#xff1a;视学算法今天分享一篇发表在ACL2020上关于KGQA的文章《Improving Multi-hop Question Answering over Knowledge Graphs using Know…

ftp设置

iis FTP服务器&#xff0c;隔离多用户配置操作 2009-12-03 19:14IIS6 FTP服务多用户配置IIS6是微软捆绑在Windows Server 2003中发布的一款优秀的Web服务器组件&#xff0c;随着Windows Server 2003在服务器领域的广泛应用&#xff0c;Web服务器大量使用了IIS6作为服务器软件&…

Nginx反向代理服务器

安装Nginxyum -y install nginx修改并添加配置文件vi /etc/nginx/nginx.conf在HTTP模块中添加&#xff1a;client_header_timeout 3000; client_body_timeout 3000; fastcgi_read_timeout 3000; client_max_body_size 32m; fastcgi_buffers 8 128k; fastcgi_buffer_size 128k; …

grails springboot_groovy 使用spring boot

<?xml version"1.0"encoding"UTF-8"?>4.0.0groovy-springgroovy-spring1.0-SNAPSHOTjarorg.springframework.bootspring-boot-starter-parent1.5.2.RELEASEcom.ktvme.Mainorg.springframework.bootspring-boot-starter-testtestmysqlmysql-connect…

10w行级别数据的Excel导入优化记录

点击上方“方志朋”&#xff0c;选择“设为星标”回复”666“获取新整理的面试文章作者&#xff1a;后青春期的Keatswww.cnblogs.com/keatsCoder/p/13217561.html需求说明项目中有一个 Excel 导入的需求&#xff1a;缴费记录导入由实施 / 用户 将别的系统的数据填入我们系统中的…