workset 和 private 的区别

本文详细解释了计算机内存管理中的关键概念,如WorkingSet、PrivateBytes和VirtualBytes等,并通过实例帮助理解这些概念的区别及应用场景。

总结:

1)Working Set看成一个进程可以用到(但不一定会使用)的物理内存。即不引起page fault异常就能够访问的内存。

     Working Set包含了可能被其他程序共享的内存, 例如DLL就是一个典型的可能被其他程序共享的资源。

     所以所有进程的Working Set加起来有可能大于实际的物理内存。

2)Private Bytes是只被本进程用占用的虚拟地址空间,不包括其他进程共享的内存。

     Private Bytes既包括不引起page fault异常就能够访问的内存也包括引起page fault异常才能够访问的内存。

     所以一般Private Bytes大于Working Set。但是如果一个进程和其他进程共享较多内存,也可能造成Working Set大于Private Bytes。

3)Virtual Byte是整个进程占用的全部虚拟地址空间。32位Windows用户模式下,进程最大可以使用2GB,可以通过修改Boot.ini文件扩展为最大可以使用到3GB。

4)Windows Task Manager中看到内存使用量是Working Set。

 

==================================================

原文:

http://my.opera.com/Returner/blog/show.dml/573233

http://www.cnblogs.com/awpatp/archive/2010/01/26/1656651.html

 

*The working set of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. *The working set of a process consists of the set of resident physical pages visible to the process. When a thread accesses a page that is not in the working set of its process, a page fault occurs. Before the thread can continue, the virtual memory manager must add the page to the working set of the process. A larger working set increases the probability that a page will be resident in memory, and decreases the rate of page faults. 可以把Working Set看成一个进程可以用到(但不一定会使用)的物理内存(物理内存页的集合)。内存管理单元在进行虚拟内存地址到物理内存地址转换时,如果虚拟地址不在物理内存中,会引起page fault异常。足够的WorkingSet就可以保证常用的虚拟地址都位于物理内存中,减少这种异常,避免了异常处理(例如访问swap文件,将页面读入物理内存)带来的性能损耗。因此,对于时间比较敏感的程序,应该分配足够的WorkingSet以保证程序性能。

*When you increase the working set size of an application, you are taking away physical memory from the rest of the system. *Suppose you have a 16-megabyte system and you set your minimum to four megabytes. In effect, this takes away four megabytes from the system. Other applications may be unable to get their minimum working set. 可见,Working Set是被真实地从物理内存中划分出来的。一个程序占用了多少Working Set,物理内存中就有多少空间不能被其它程序使用。

*Reducing memory consumption is always a beneficial goal. If you call SetProcessWorkingSetSize(0xffffffff, 0xffffffff), this tells the system that your working set can be released. This does not change the current sizing of the working set, it just allows the memory to be used by other applications. It is a good idea to do this when your application goes into a wait state. *Windows NT 3.5 allows processes to increase their working set size by using SetProcessWorkingSetSize(). This API is also useful to trim your minimum working set size if you want to run many processes at once, because each process has the default minimum working set size reserved, no matter how small the process actually is. Windows会为每个进程保留一个默认数值的working set,然而这个保留的Working set可能会比该process实际需要的大。可以用SetProcessWorkingSetSize()来对进程的Working set进行裁剪,只保留进程目前已经占用的页面,空闲的就释放掉给其它应用使用。

 

一个有趣的问题是, working set指目前程序所消耗的物理内存, private bytes指的是commit的内存, 那么为什么有些进程的working set比private bytes还大? 要回答这个问题, 需要仔细看看两者的定义:

  • "Working Set refers to the numbers of pages of virtual memory committed to a given process, both shared and private."
  • "Private Bytes is the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes."

所以, Working Set包含了可能被其他程序共享的内存, 而Private Bytes只包括被当前进程使用的内存.

 

DLL是一个典型的可能被其他程序共享的资源. DLL的加载使用文件映像, 因此包含DLL的物理内存可以被同时映像到多个进程上. 所以在进程中加载DLL的内存只能算到working set上, 而不能被算到private bytes上.

 

在解决内存问题的时候Shared的部分一般可以不用考虑.

一个进程使用内存的时候, 它占用的内存会被分为两部分, 一部分是working set, 另一部分是private byte减去working set. 其中working set是贮存在物理内存中的, 而剩下的另一部分是paging file, 存在磁盘上.

 

一般来说把所有进程的working set加起来会比你机器上所拥有的物理内存要大, 这是因为有Shared的资源(比如DLL)的缘故.

 

Virtual Bytes.

The current size, in bytes, of the virtual address space for this process. The virtual address space limit of a user mode process is 2 GB, unless 3 GB address space is enabled by using the /3GB switch in boot.ini.

 

原文:

Virtual Bytes are the total virtual address space occupied by the entire process, including memory-mapped files such as shared DLLs. This is like the working set except it includes data that has already been paged out and is sitting in a pagefile somewhere. The total virtual bytes used by every process on a system under heavy load will add up to significantly more memory than the machine actually has.

翻译:

Virtual Byte是整个进程占用的全部虚拟地址空间, 包括诸如共享dll在内的内存映射文件. 它跟working set很像, 不一样的是, 它还得算上已经被page out的存放在别的什么地方的pagefile中的数据. 一个高负荷系统中所有进程的全部的virtual bytes加起来, 会比机器实际拥有的内存多很多.

 

个人理解

===============

假设我有一台机器, 机器有物理内存1024M. 机器上面仅运行着三个进程A, B, C.

下面的情况是可能的:

A和B仅共用一个叫做common.dll的库文件. common.dll为A分配了10M的内存, 为B分配了20M内存.

common.dll本身占30M内存.

A的可执行程序以及其数据本身占用了40M, B的使用了50M, C的使用了60兆.

A的可执行程序本身使用的内存中有5兆不在内存中, 在pagefile中.

A没有引用其他的dll文件.

 

那么A的private bytes是40-5+10 = 45M

A的working set是40-5+30 = 65M

A的virtual bytes是40+30+10=80M

转载于:https://www.cnblogs.com/xwj-pandababy/articles/3180493.html

package com.xieli.xielitraceapp.view.work.bean; public class QrCodeBean { private int code; private List list; private List2 list2; private String msg; private Obj obj; private int total; private int total2; public class Obj { private String checkBottleIsInOrder; public String getCheckBottleIsInOrder() { return checkBottleIsInOrder; } public void setCheckBottleIsInOrder(String checkBottleIsInOrder) { this.checkBottleIsInOrder = checkBottleIsInOrder; } private String bundleOrCylinder; private String bottleNumber; private String bottleProducerId; private String checkCompany; private int checkResult; private String cylinderType; private String fillingCompany; private String fillingCompanyAddress; private String fillingCompanyPhone; private String fillingCzPressure; private String fillingDate; private String fillingMediumName; private String fillingPerson; private String id; private String inspectionDate; private String nextInspectionDate; private String produceName; private String productionDate; private String registrationNo; private String unitSerialNumber; private String fillingMediumId; private String realWeight; private String emptyHeavy; private String warehouseName;//所属仓库名称 private String recordId; //气瓶epc编号 private String epc; //充装步骤 private String fillingStep; //集装格标识 private String bundleFlag; private String specificationId; private List<Cylinder> cylinderList; public String getSpecificationId() { return specificationId; } public void setSpecificationId(String specificationId) { this.specificationId = specificationId; } public String getRecordId() { return recordId; } public void setRecordId(String recordId) { this.recordId = recordId; } public String getBundleOrCylinder() { return bundleOrCylinder; } public void setBundleOrCylinder(String bundleOrCylinder) { this.bundleOrCylinder = bundleOrCylinder; } public List<Cylinder> getCylinderList() { return cylinderList; } public void setCylinderList(List<Cylinder> cylinderList) { this.cylinderList = cylinderList; } public String getBundleFlag() { return bundleFlag; } public void setBundleFlag(String bundleFlag) { this.bundleFlag = bundleFlag; } public String getWarehouseName() { return warehouseName; } public void setWarehouseName(String warehouseName) { this.warehouseName = warehouseName; } public String getEpc() { return epc; } public void setEpc(String epc) { this.epc = epc; } public String getFillingStep() { return fillingStep; } public void setFillingStep(String fillingStep) { this.fillingStep = fillingStep; } public String getEmptyHeavy() { return emptyHeavy; } public void setEmptyHeavy(String emptyHeavy) { this.emptyHeavy = emptyHeavy; } public String getRealWeight() { return realWeight; } public void setRealWeight(String realWeight) { this.realWeight = realWeight; } public String getFillingMediumId() { return fillingMediumId; } public void setFillingMediumId(String fillingMediumId) { this.fillingMediumId = fillingMediumId; } public void setBottleNumber(String bottleNumber) { this.bottleNumber = bottleNumber; } public String getBottleNumber() { return bottleNumber; } public void setBottleProducerId(String bottleProducerId) { this.bottleProducerId = bottleProducerId; } public String getBottleProducerId() { return bottleProducerId; } public void setCheckCompany(String checkCompany) { this.checkCompany = checkCompany; } public String getCheckCompany() { return checkCompany; } public void setCheckResult(int checkResult) { this.checkResult = checkResult; } public int getCheckResult() { return checkResult; } public void setCylinderType(String cylinderType) { this.cylinderType = cylinderType; } public String getCylinderType() { return cylinderType; } public void setFillingCompany(String fillingCompany) { this.fillingCompany = fillingCompany; } public String getFillingCompany() { return fillingCompany; } public void setFillingCompanyAddress(String fillingCompanyAddress) { this.fillingCompanyAddress = fillingCompanyAddress; } public String getFillingCompanyAddress() { return fillingCompanyAddress; } public void setFillingCompanyPhone(String fillingCompanyPhone) { this.fillingCompanyPhone = fillingCompanyPhone; } public String getFillingCompanyPhone() { return fillingCompanyPhone; } public void setFillingCzPressure(String fillingCzPressure) { this.fillingCzPressure = fillingCzPressure; } public String getFillingCzPressure() { return fillingCzPressure; } public void setFillingDate(String fillingDate) { this.fillingDate = fillingDate; } public String getFillingDate() { return fillingDate; } public void setFillingMediumName(String fillingMediumName) { this.fillingMediumName = fillingMediumName; } public String getFillingMediumName() { return fillingMediumName; } public void setFillingPerson(String fillingPerson) { this.fillingPerson = fillingPerson; } public String getFillingPerson() { return fillingPerson; } public void setId(String id) { this.id = id; } public String getId() { return id; } public void setInspectionDate(String inspectionDate) { this.inspectionDate = inspectionDate; } public String getInspectionDate() { return inspectionDate; } public void setNextInspectionDate(String nextInspectionDate) { this.nextInspectionDate = nextInspectionDate; } public String getNextInspectionDate() { return nextInspectionDate; } public void setProduceName(String produceName) { this.produceName = produceName; } public String getProduceName() { return produceName; } public void setProductionDate(String productionDate) { this.productionDate = productionDate; } public String getProductionDate() { return productionDate; } public void setRegistrationNo(String registrationNo) { this.registrationNo = registrationNo; } public String getRegistrationNo() { return registrationNo; } public void setUnitSerialNumber(String unitSerialNumber) { this.unitSerialNumber = unitSerialNumber; } public String getUnitSerialNumber() { return unitSerialNumber; } } public class List { } public class List2 { } public void setCode(int code) { this.code = code; } public int getCode() { return code; } public void setList(List list) { this.list = list; } public List getList() { return list; } public void setList2(List2 list2) { this.list2 = list2; } public List2 getList2() { return list2; } public void setMsg(String msg) { this.msg = msg; } public String getMsg() { return msg; } public void setObj(Obj obj) { this.obj = obj; } public Obj getObj() { return obj; } public void setTotal(int total) { this.total = total; } public int getTotal() { return total; } public void setTotal2(int total2) { this.total2 = total2; } public int getTotal2() { return total2; } public static class Cylinder { private String id; private String bottleNumber; private String bottleProducerId; private String productionDate; private String epc; private String fillingMediumId; private String emptyHeavy; private String volume; private String weight; private String designingWallThickness; private String nominalPressure; private String inspectionDate; private String nextInspectionDate; private int inspectionNumber; private String bottleState; private String warehouseCompanyId; private String affiliatedCompanyId; private String platformNumber; private String currentLocation; private String escrowCustomerId; private int bundleFlag; private int transportStatus; private String leasingCustomerId; private String bundleRecordId; private String isEscrow; private String payCustomerId; private String specificationId; private String registrationNo; private int fillingStep; private int fillingNumber; private String province; private String city; private String county; private String scrapTime; private String createUserName; private long createTime; private String updateUserName; private long updateTime; private String unitSerialNumber; private int isSendCard; private String realWight; private String tid; private int isDelete; private int isErrorInfo; private String remark; private int isPrint; private String quickMark; private String errorReason; private String bottleProducer; private String fillingMedium; private String medium; private String currentWarehouse; private String hanliang; private String isUpdateWeight; private int stopOrStartUse; private int uploadScrap; private int peiqiState; private String peiqiOrderId; private String qrcode; // GetterSetter方法... } } 修复这个实体类
07-05
在 IntelliJ IDEA 中,虽然没有完全等同于 Eclipse 的 **Work Set** 功能,但你可以通过 **模块分组(Module Groups)** **Scope(作用域)** 来实现类似的功能:**将项目中的多个模块进行逻辑分组,只显示你关心的模块**。 --- ### ✅ 方法一:使用 Module Groups 分组模块 IDEA 支持为模块设置分组,这样在项目视图中可以按组折叠/展开模块。 #### 🔧 操作步骤: 1. 打开项目结构设置: - `File` → `Project Structure...`(或快捷键 `Ctrl + Alt + Shift + S`) 2. 在左侧选择 `Modules` 3. 右键某个模块 → `Move into Group` → 选择或新建一个组名(例如:`MyGroup`) 4. 你也可以选择多个模块 → 右键 → `Move into Group` → 创建新组 5. 在项目视图中,IDEA 会根据模块组进行折叠显示 #### 📌 示例: ``` Project └── Modules ├── GroupA │ ├── module-a │ └── module-b └── GroupB ├── module-c └── module-d ``` --- ### ✅ 方法二:使用 Scope 自定义视图(推荐) 你可以创建一个 **Scope(作用域)**,只显示你关心的模块或文件,然后在项目视图中切换显示模式。 #### 🔧 操作步骤: 1. 打开项目视图右上角的下拉菜单(显示 "Project" 的地方) 2. 点击 `Modify View` → 勾选 `Flatten Packages`、`Compact Middle Packages` 等(可选) 3. 再次点击视图下拉菜单 → 选择 `Customize View` → `Configure Visibility...` 4. 点击 `+` 添加一个 Scope: - 选择 `Shared` 或 `Private` - 使用 `+` 添加你关心的模块目录 - 设置过滤规则(如只显示某些目录或模块) 5. 设置完成后,在项目视图下拉菜单中选择你定义的 Scope,即可只显示相关模块 --- ### ✅ 方法三:使用多个窗口或项目(备用) 如果你需要完全隔离模块查看,也可以: - 打开多个 IDEA 窗口,每个窗口打开一个子项目(适用于多模块项目中使用 `include` 的方式) - 或者使用不同的 `.idea` 配置文件夹,只加载部分模块 --- ### ✅ 方法四:使用“Scope”过滤搜索、查找引用等 Scope 不仅可以控制视图,还可以用于: - 查找类/文件(`Ctrl + N` / `Ctrl + Shift + N`)时限定范围 - 查找引用(Find Usages) - 代码分析(Analyze) - 运行/调试配置 --- ### ✅ 总结 | 功能 | 描述 | 推荐程度 | |------|------|----------| | Module Groups | 模块分组展示 | ✅ 推荐 | | Scope | 自定义显示模块/目录 | ✅✅ 强烈推荐 | | 多窗口/项目 | 完全隔离模块 | ⚠️ 备用方案 | | Find/Analyze 时使用 Scope | 提高效率 | ✅ 推荐 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值