是否可以锁定应用程序中常用控件使用的内存? [英] Is it possible to lock memory used by common controls in my application?

查看:35
本文介绍了是否可以锁定应用程序中常用控件使用的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个对其数据进行加密的应用程序.然后,在用户输入密码后,它可以使用应用程序的 UI 显示未加密的信息.我的目标是在 RAM 中尽量减少明文数据的暴露.为此,我想尽可能地防止将其交换到磁盘.

I'm writing an application that encrypts its data. It can then display it unencrypted using the app's UI after a user enters password. My goal is to minimize exposure of plaintext data while in RAM. For that I want to prevent swapping it to disk as much as possible.

我知道我可以调整进程的工作集(通过调用 SetProcessWorkingSetSize API),然后将这些敏感页面锁定在 RAM 中(通过调用 VirtualLock.)理论上,这应该最大限度地减少它被写入磁盘的机会.

I know that I can adjust my process's working set (by calling SetProcessWorkingSetSize API) and then lock those sensitive pages in RAM (by calling VirtualLock.) That, in theory, should minimize the chances of it being written to disk.

我的问题是,我可以对对话框窗口中的公共控件使用的内存做同样的事情,即在 编辑框组合框,最重要的是RichEdit 控件?

The question I have is, can I do the same with the memory that is used by the common controls in my dialog window, namely in Edit boxes, combo boxes, and most importantly RichEdit control?

附注.我假设他们都使用来自 用于我的进程.正确吗?

PS. I'm assuming that they all use data from the heap for my process. Correct?

看到下面的所有评论,我需要澄清一下.说锁",我的意思不是用挂锁和钥匙锁住它,这样就没有人可以看到它".我的意思是,像使用 VirtualLock API 一样锁定它.

Seeing all the comments below I need to clarify. By saying "lock", I don't mean, "lock it with a padlock and key so that no one can see it." I meant, lock it as with the VirtualLock API.

推荐答案

您可以使用 EM_SETHANDLE 为编辑控件的初始分配设置句柄,然后响应 EN_ERRSPACE当(如果)空间不足并需要更多空间时.

You can use EM_SETHANDLE to set a handle for an edit control's initial allocation, then respond to EN_ERRSPACE when (if) it runs out of space and needs more.

从那里开始,您还可以在该内存块上使用 VirtualLock 以将其尽可能多地保留在 RAM 中.如果您要经常这样做,您可能需要考虑对控件进行超类化,以免在任何地方复制代码.

From there, it's up to you to also use VirtualLock on that block of memory to keep it in RAM as much as possible. If you're going to do this a lot, you probably want to consider superclassing the control(s) to keep from duplicating the code everywhere.

不管好坏,我不相信富文本控件有等价物.

For better or worse, I don't believe there's an equivalent for rich text controls though.

这篇关于是否可以锁定应用程序中常用控件使用的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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