将用户限制在特定的空间 [英] Restricting user to particular space

查看:70
本文介绍了将用户限制在特定的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序将用户限制为内存中的预定义空间,如果用户尝试访问的内存超出了分配的内存,那么它应该不允许并显示错误消息.该应用程序还会分配内存.所以请帮助我列出可以使用的C ++功能.

在此先感谢

解决方案

用户无法控制内存分配,因此这不是您需要关注的事情,除非您的应用程序提供了一些功能来分配内存


1.如果您编写一个应用程序,则该应用程序会消化它的单独的虚拟内存空间,而天堂或地狱中没有办法影响其他应用程序的内存空间,这又从操作系统获得了自己的虚拟内存空间.您需要编写一个操作系统来控制它!

2.如果您想编写一个或子系统,那么您当然可以提供影响使用该子系统的每个应用程序 的机制.

假设您的意思是后者,则可以简单地覆盖全局运算符::operator new()::operator delete().如果那是您希望实现的目标,那么也许您应该在Google上搜索set_new_handler,我听说这是一个更安全的版本(不过我自己从来没有尝试过类似的方法).


I want my application to restrict user to a predefined space in memory and if user tries to access more than the alloted memory then it should not allow and should display a error message.The applicaion also allocates the memory.So Please help me out what C++ functionality can be used.

Thanks in advance

解决方案

The user has no control over memory allocation so this is not something you need to be concerned about, unless your application offers some feature that allocates memory on his behalf.


1. If you write an application, then this application gest it''s separate virtual memory space, and there is no way in heaven or hell to influence the memory space of other applications, which in turn get their own virtual memory space from the OS. You''d need to write an OS to control that!

2. If you want to write a library or subsystem, then you can of course provide mechanisms that influence every application that uses this subsystem.

Assuming you mean the latter, you can simply override the global operators ::operator new() and ::operator delete(). If that is what you wish to accomplish, then maybe you should google for set_new_handler, which I''ve heard is a somewhat safer version (never tried anything like that myself though).


这篇关于将用户限制在特定的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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