数组的内存分配 - 分页 [英] Array memory allocation - paging

查看:150
本文介绍了数组的内存分配 - 分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道答案是对Java,C#和C ++一样,所以我归类他们。答所有语言将是很好的。

Not sure if the answer would be the same for Java, C# and C++, so I categorized all of them. Answer for all languages would be nice.

所有的日子,我一直在想,如果我分配阵列的所有单元都应该在一个连续空间。所以,如果没有足够的内存在一块系统也将提高内存不足的异常。

All days I've been thinking, that if I allocate array all the cells would be in one, contiguous space. So if there isn't enough memory in one piece in system there will be raised out of memory exception.

是不是所有的权利,我说什么?或者是有可能,那分配的数组将分页?

Is it all right, what I said? Or is there possibility, that allocated array would be paginated?

推荐答案

C ++数组是连续的,这意味着内存有连续的地址,即它在虚拟地址空间连续的。它不必是物理地址空间连续的,因为现代处理器(或它们的存储器子系统)具有大的地图,与物理页的虚拟页相关联。在用户模式下运行的进程从来没有看到他们的阵列的物理地址。

C++ arrays are contiguous, meaning that the memory has consecutive addresses, i.e. it's contiguous in virtual address space. It need not be contiguous in physical address space, since modern processors (or their memory subsystems) have a big map that associates virtual pages with physical pages. Processes running in user mode never see physical addresses of their arrays.

我想在实践中的大部分或全部的Java实现是相同的。但是,程序员永远不会看到一个数组元素的实际地址,只对数组的引用和手段,建立索引。因此,在理论上,Java实现可能断裂阵列和隐藏在 [] 运营商这一事实,尽管JNI代码仍然可以查看C ++风格的阵列,在这点上将需要连续的块。这是假设有没有在JVM规范有关数组的布局,这jarnbjo告诉我没有。

I think in practice most or all Java implementations are the same. But the programmer never sees an actual address of an array element, just a reference to the array and the means to index it. So in theory, a Java implementation could fracture arrays and hide that fact in the [] operator, although JNI code can still view the array in the C++ style, at which point a contiguous block would be needed. This is assuming there's nothing in the JVM spec about the layout of arrays, which jarnbjo tells me there isn't.

我不知道C#,但我预计情况很类似于Java - 你能想象一个实现可能使用 [] 经营者隐瞒事实,一个数组是不是在虚拟地址空间连续的。有人获得一个指针到其中的幌子将尽快失败。

I don't know C#, but I expect the situation is pretty similar to Java - you can imagine that an implementation might use the [] operator to hide the fact that an array isn't contiguous in virtual address space. The pretense would fail as soon as someone obtained a pointer into it.

请注意,如果你分配一些大对象类型的数组,然后在C ++中的数组实际上是许多大型结构奠定终端到终端,所以连续分配所需的大小取决于大小物体。在Java中,对象的数组是真的引用数组。所以这是一个小的连续的块比C ++数组。对于原生类型它们是相同的。

Note that if you allocate an array of some large object type, then in C++ the array actually is that many large structures laid end-to-end, so the required size of the contiguous allocation depends on the size of the object. In Java, an array of objects is "really" an array of references. So that's a smaller contiguous block than the C++ array. For native types they're the same.

这篇关于数组的内存分配 - 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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