简体   繁体   English

如何减少Socket应用程序的C#内存使用率

[英]How to reduce C# memory usage for Socket Application

I developed a simple UDP message server and client application in Windows, the server can send a message to the client but the client can't send anything, they are only listening. 我在Windows中开发了一个简单的UDP消息服务器和客户端应用程序,该服务器可以向客户端发送消息,但是客户端什么也不能发送,它们只是在监听。 the problem is the client application is use quite big memory usage is about 7M when it's listening and 9M when it received a packet. 问题是客户端应用程序正在使用很大的内存,在侦听时约为7M,而在收到数据包时约为9M。 Could I reduce the memory usage into at least less then 1M? 我可以将内存使用量减少到至少少于1M吗?

How are you measureing your memory footprint? 您如何测量内存占用量? Any managed .net application, even the smallest typically has a shared working set of around 50 MBs, the actual memory footprint of your app is much smaller than that. 任何托管的.net应用程序,即使最小的应用程序,通常都具有大约50 MB的共享工作集,您的应用程序的实际内存占用空间远小于此。

Have you tried calling GC.GetTotalMemory to look at the actual managed memory usage? 您是否尝试过调用GC.GetTotalMemory来查看实际的托管内存使用情况?

Much of this burden is the overhead of running the whole CLR system, garbage collection etc. If you're super-sensitive to memory footprint (<10-20Mb) then the CLR may not be for you. 其中的大部分负担是运行整个CLR系统,垃圾回收等的开销。如果您对内存占用量(<10-20Mb)非常敏感,则CLR可能不适合您。 Even a basic HelloWorld private working set is over 4Mb of RAM. 甚至基本的HelloWorld专用工作集都超过4Mb的RAM。

If you are sensitive to footprint, you might be best served by looking to a true ahead-of-time compiled language like C/C++ etc. 如果您对足迹敏感,则最好使用真正的提前编译的语言(例如C / C ++等)来为您提供最好的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM