var x = new Int64()需要多少内存? [英] How much memory is required for var x = new Int64()?

查看:91
本文介绍了var x = new Int64()需要多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到与Java内存管理和C#(.NET)内存管理有很多相似之处.根据来自IBM的You Tube视频( https://www.youtube.com/watch?v=FLcXf9pO27w )  java 此语句需要224位

I've noticed a lot of similarities with java memory management and C# (.NET) memory management. According to this You Tube  video from IBM (https://www.youtube.com/watch?v=FLcXf9pO27w) java requires 224 bits for this statement

Integer x = new Integer(10);


哇!

此语句需要C#占用多少内存?

How much memory does C# require for this statement?

var x = new Int64(); x=10;

我怀疑Java需要超过224位,因为该视频没有讨论垃圾回收器碎片整理内存并将值10的位置移动到位置的额外开销(要求变量x指向新位置)

I suspect java requires more than 224 bits because that video does not discuss the additional overhead for the garbage collector to de-fragment memory and move the location of the value of 10 (requiring that the variable x point to a new location).

那么C#如何进行内存管理(特别是碎片整理)?它是否保留着巨大的变量及其值的链接列表?还是变量实际上只是指向指针主数组的索引,其中指针主数组中的每个条目 指向包含值10的实际整数对象?如果是这样,当某些变量在函数末尾超出范围时,该主指针数组是否包含空数组单元?

So how does C# does memory management (and de-fragmentation specifically) work? Does it keep huge linked lists of variables and their values? Or is a variable really just an index into a master array of pointers where each entry in the master array of pointers points to the actual integer object containing the value 10? If so, does this master array of pointers contain vacant array cells as some variables go out of scope at the end of a function?

赞!这很复杂!也许有人可以指出我对此的一些很好的讨论?

Yikes! This is complex! Perhaps someone could point me to some good discussions on this?

谢谢

齐格弗里德

siegfried heintze

siegfried heintze

推荐答案

齐格弗里德,

谢谢您在这里发布.

>> 对于您的问题,您可以使用 GC.GetTotalMemory方法(布尔值) 获取当前认为已分配的字节数.参数指示此方法是否可以在返回之前等待一小段时间,以允许系统收集垃圾 并完成对象.

For your question, you could use GC.GetTotalMemory Method (Boolean) retrieves the number of bytes currently thought to be allocated. A parameter indicates whether this method can wait a short interval before returning, to allow the system to collect garbage and finalize objects.

这是输出.语句的内存为8192.

Here is the output. The memory of statement is 8192.


>> 关于此问题,您可以参考MSDN文章 垃圾收集基础.

For the this question, you could refer to the MSDN article Fundamentals of Garbage Collection.

我希望这会有所帮助.

最好的问候,

温迪


这篇关于var x = new Int64()需要多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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