增加虚拟字节的操作和函数

发布于 2024-08-08 06:07:03 字数 1576 浏览 5 评论 0原文

由于 Windows 中的 32 位进程出现一些内存不足问题,我开始使用性能监视器来记录该进程的某些计数器。

虽然虚拟字节比私有字节和工作集都高是正常的,但我发现在我的例子中存在很大的差异,虚拟字节比私有字节和工作集都高很多

哪些特定操作和 Win32/CRT 函数(C 或 C++ 中)会增加虚拟字节,但不会增加私有字节和工作集?

如果我理解性能监视器中不同计数器的描述,我想这将是某种共享资源。


由于在不同版本的 Windows 中以及同一版本的 Windows 中的不同应用程序中用于内存计数器的命名约定似乎存在一些(至少可以说)混乱,因此我整理了以下内容:

来自 MSDN 的信息

根据至 MSDN - Windows 版本的内存限制 ,在 32 位 Windows 中,每个 32 位进程的用户模式虚拟地址空间限制通常为 2 GB。使用 IMAGE_FILE_LARGE_ADDRESS_AWARE4G​​T 时,最大可达 3 GB。

下面是性能监视器中不同计数器的描述以及任务管理器中的相应列以及保存信息的 Win32 结构,根据 MSDN - 内存性能信息

虚拟字节

Virtual Bytes 是进程正在使用的虚拟地址空间的当前大小(以字节为单位)。虚拟地址空间的使用并不一定意味着磁盘或主内存页面的相应使用。虚拟空间是有限的,进程会限制其加载库的能力。

任务管理器 XP:不适用
任务管理器 Vista:不适用
结构:MEMORYSTATUSEX.ullTotalVirtual-MEMORYSTATUSEX.ullAvailVirtual

私有字节

Private Bytes 是该进程已分配且不能与其他进程共享的内存的当前大小(以字节为单位)。

任务管理器 XP:虚拟机大小
任务管理器 Vista:提交大小
结构:PROCESS_MEMORY_COUNTERS_EX.PrivateUsage

工作集

工作集是此进程的工作集的当前大小(以字节为单位)。工作集是进程中线程最近接触的内存页集。如果计算机中的可用内存高于阈值,则即使页面未在使用中,它们也会保留在进程的工作集中。当可用内存低于阈值时,将从工作集中修剪页面。如果需要它们,它们将在离开主内存之前软故障回到工作集中。

任务管理器 XP:内存使用情况
任务管理器 Vista:工作集
结构:PROCESS_MEMORY_COUNTERS_EX.WorkingSetSize

Having some out-of-memory problems with a 32-bit process in Windows I begun using Performance Monitor to log certain counters for that process.

Though it is normal that Virtual Bytes is higher than both Private Bytes and Working Set, I found that in my case there was a substantial difference, Virtual Bytes was much higher than both Private Bytes and Working Set.

What specific operations and Win32/CRT functions (in C or C++) would increase Virtual Bytes but not Private Bytes and Working Set?

I guess it would be some kind of shared resources, if I understand the description of the different counters in Performance Monitor.


As there seems to be some (to say the least) confusion on the naming convention to use for the memory counters in different releases of Windows as well in different applications in the same release of Windows, I put together the following:

Information from MSDN

According to MSDN - Memory Limits for Windows Releases, the user-mode virtual address space limit in 32-bit Windows for each 32-bit process is normally 2 GB. It can be up to 3 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4GT.

Below is a description of the different counters in Performance Monitor along with the corresponding columns in Task Manager and the Win32 structure which holds the information, according to MSDN - Memory Performance Information.

Virtual Bytes

Virtual Bytes is the current size, in bytes, of the virtual address space the process is using. Use of virtual address space does not necessarily imply corresponding use of either disk or main memory pages. Virtual space is finite, and the process can limit its ability to load libraries.

Task Manager XP: N/A
Task Manager Vista: N/A
Structure: MEMORYSTATUSEX.ullTotalVirtual-MEMORYSTATUSEX.ullAvailVirtual

Private Bytes

Private Bytes is the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes.

Task Manager XP: VM Size
Task Manager Vista: Commit Size
Structure: PROCESS_MEMORY_COUNTERS_EX.PrivateUsage

Working Set

Working Set is the current size, in bytes, of the Working Set of this process. The Working Set is the set of memory pages touched recently by the threads in the process. If free memory in the computer is above a threshold, pages are left in the Working Set of a process even if they are not in use. When free memory falls below a threshold, pages are trimmed from Working Sets. If they are needed they will then be soft-faulted back into the Working Set before leaving main memory.

Task Manager XP: Mem Usage
Task Manager Vista: Working Set
Structure: PROCESS_MEMORY_COUNTERS_EX.WorkingSetSize

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兲鉂ぱ嘚淚 2024-08-15 06:07:04

你的编程语言是什么?

在托管框架中,私有字节表示由非托管资源分配的数据。
而虚拟字节表示总内存使用量(非托管和托管数据)。

因此,在此类框架中,私有字节和虚拟字节之间存在显着差异是很常见的。

What is your programming language?

In managed frameworks, private bytes represent data that is allocated by unmanaged resources.
Whereas virtual bytes represent the total memory usage (unmanaged and managed data).

Thus, it is very common to see substantial differences between private and virtual bytes in such frameworks.

以酷 2024-08-15 06:07:03

我现在能想到的(可能)增加虚拟字节而不增加私有字节的事情:

  • 二进制文件通常是共享的(即不是私有的),但占用了大量的地址空间。这甚至可能大于二进制文件的大小

  • 使用 VirtualAlloc 保留顺序地址空间而不提交/访问它。自定义内存管理器可能会这样做。

  • 使用内存映射文件(不完全访问它)

Things that (may) increase virtual bytes without increasing private bytes I can think of right now:

  • Binaries are often shared (i.e. not private), but occupy significant address space. This can be even larger than the size of the binary

  • Using VirtualAlloc to reserve sequential address space without committing / accessing it. Custom Memory Managers might do that.

  • Using a memory mapped file (without completely accessing it)

风向决定发型 2024-08-15 06:07:03

通过使用 VirtualAlloc,您可以分配虚拟地址空间,而无需实际分配任何物理内存。这应该会增加“虚拟字节”计数,但不会增加您的工作集大小。

内存不足可能是由于保留了过多的地址空间而导致地址空间耗尽。

By using VirtualAlloc, you can allocate virtual address space without actually allocating any physical memory. That should increase "virtual byte" count, but not your working set size.

The out of memory could be caused by running of address space because reserving too much address space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文