优化我的应用程序 [英] Optimizing my application

查看:70
本文介绍了优化我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经超越了我的程序中的功能点,现在我正在尝试优化。当我开始写作的时候,我仍然在学习很多东西,所以我并没有做正确的事情。办法。一切正常,但我相信我可以减少记忆。我最近一直很清楚这一点,所以我一直在打开任务管理器并运行我的应用程序,通过它的各种功能来查看内存是如何受到影响的。


我注意到当我使用图像和打开文件时,即使关闭文件流和二进制读取器访问文件,它仍然不会释放内存资源。

我有一个程序打开一个存档文件,一个包含Xbox 360主题的文件。该程序读取有关主题的所有信息,让用户预览单个文件,保存这些单个文件,以及转储所有文件。主题文件只有12.5MB。我的程序的空闲内存使用量不到11MB。当我点击打开时按钮显示openFileDialog,内存使用量跃升至21MB。当我实际打开主题文件时,它会跳到不到50MB的内存使用量。为什么打开一个12.5MB的文件会增加30MB?我检索了各种各样的信息,并且我循环遍历4096个字节块64次(一次读取64个字节)以获取有关各个文件的信息。我只是创建一个字节数组并将其传递给结构,然后将结果信息打印到listView。


我确定我已经处理了所有我能做的事情,但处理我的对象似乎并没有释放资源。我有一个关闭文件处理和关闭我正在使用的所有各种文件和读者和图像的按钮,但内存使用率保持不变。这是为什么?


是否有一种简单的方法来优化我的程序,如果没有简单的方法,有没有办法可以打印一些软调试信息到程序告诉我它使用了多少内存以及用于什么资源?

I''ve gotten past the point of functionality in my program, now I''m trying to optimize. When I started writing I was still learning about a lot of things, so I didn''t quite do things the "right" way. Everything works, but I''m sure I could make it use less memory. I''ve been getting pretty conscious about this lately, so I''ve been opening up Task Manager and running my app, putting it through it''s various functions to see how the memory is affected.

I''ve noticed that when I use images and open files, even after I close the filestream and binaryreader accessing the file, it still doesn''t release the memory resources.

I have a program that opens a sort of archive file, a file containing a theme for the Xbox 360. The program reads all the information about the theme and lets the user preview individual files, save those individual files, and dump all the files. The theme file is only 12.5MB. My program''s idle memory usage is just under 11MB. When I click the "Open" button to show the openFileDialog, the memory usage jumps to 21MB. When I actually open the theme file, it jumps up to just under 50MB of memory usage. Why is it going up 30MB just to open a 12.5MB file? There are various pieces of information I retrieve, and I loop through a 4096 byte block 64 times (reading 64 bytes at a time) to get the information about the individual files. I just create a byte array and pass it to a struct, then print the resulting information to a listView.

I''m sure I''ve disposed of all the things I can, but disposing my objects doesn''t seem to release the resources. I have a "Close File" button that disposes and closes all the various files and readers and images I''m using, but the memory usage stays the same. Why is this?

Is there a simple way to optimize my program, and if there''s no simple way, is there a way I can print some soft of debug info to the program telling me how much memory it''s using and for what resources?

推荐答案

''simple''和''windows memory''永远不会在一起。

''simple'' and ''windows memory'' never go together.


主题文件只有12.5MB。我的程序的空闲内存使用量不到11MB。当我点击打开时按钮显示openFileDialog,内存使用量跃升至21MB。当我实际打开主题文件时,它会跳到不到50MB的内存使用量。为什么打开一个12.5MB的文件会增加30MB?
The theme file is only 12.5MB. My program''s idle memory usage is just under 11MB. When I click the "Open" button to show the openFileDialog, the memory usage jumps to 21MB. When I actually open the theme file, it jumps up to just under 50MB of memory usage. Why is it going up 30MB just to open a 12.5MB file?



也许你正在制作你的图像的多个副本而没有意识到它。你有一个变量中的图像,以及它在picturebox.image属性中的副本......并且你将它的副本作为缩略图生成器的一部分...

Maybe you are making multiple copies of your images without realizing it. You have an image in a variable, and a copy of it in a picturebox.image property... and you make a copy of it as part of a thumbnail generator...


我只是创建一个字节数组并将其传递给结构,然后将结果信息打印到listView。
I just create a byte array and pass it to a struct, then print the resulting information to a listView.



你在一个字节中有一个图像[] *和*在一个结构*和*在一个列表视图中......有三倍的用法就在那里。

you have an image in a byte[] *and* in a struct *and* in a listview... there''s three times the usage right there.


我没有意识到在图片框中设置图片制作了它的副本,有没有办法解决这个问题?


和至于byte [],struct,listview,我将64个字节的数据,非图像传递给结构进行解析,最多64次(4096字节块中的64x64字节块。)我设置字节[每次都在循环中,因此它应该只有64字节的数据,如果有的话,它只能读取4096字节。我只是不明白为什么当我关闭文件并处理文件流时,它不会释放资源。我甚至尝试过调用GC.Collect(),没有。
I didn''t realize setting the picture in the picturebox made a copy of it, is there a way around that?

And as for the byte[], struct, listview, I''m passing 64 bytes of data, non image, to the struct for parsing, at most 64 times (64x64 byte blocks in a 4096 byte block.) I set the byte[] in the loop everytime, so it should only ever have 64 bytes of data in it, and if anything it would only be reading 4096 bytes. I just don''t get why when I close the file and dispose the filestream, it doesn''t release the resources. I even tried calling GC.Collect(), nothing.


然后它仍然在某个地方的范围内。
Then it is still within scope someplace.


这篇关于优化我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆