在运行时读取可执行文件中的数据
日安!
我有一个可执行文件(Unix 或 Windows - 它应该是交叉编译的)。如果用任何编辑器打开这个可执行文件并在最后写入一些内容 - 应用程序仍然可以完美运行。 执行时,应用程序及其所有数据都会加载到 RAM 中。因此,文件的用户写入部分也被加载到内存中。
有机会读取这些数据吗?
我需要快速访问这些数据。其他解决方法也不行,因为它花费太多时间:
- 直接从文件(在硬盘上)读取或映射它都不好,因为应用程序必须在每次运行时读取此文件,但此应用程序每秒启动很多次。
- 与另一个进程(例如保存数据的服务器)使用共享内存不是交叉编译
- 在应用程序和所谓的服务器之间使用管道不够快,恕我直言。
这就是为什么我决定在应用程序的末尾写一些东西。
提前致谢!
G'Day!
I have an executable (Unix or Windows - it should be cross-compiling). If one opens this executable by any editor and write some stuff to the end - the application would still run perfect.
On execution, the application with all its data loads to the RAM. So, the user-written part of file is also loaded into memory.
Is there any chance to read this data?
I need this data in fast access. Other workarounds are not OK, because it takes too much time:
- Reading directly from file (on hard disk) or mapping it is not fine, because the application have to read this file on each run, but this application has lots of launches per sec.
- Using shared memory with another process (something like server, which holds data) is not cross-compiling
- Using pipes between app and so-called server is not fast enough, imho.
That's why I decided to write some stuff to the end of application.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否重新发明了
我还认为您可能正在优化错误的东西。
内核[1]比我们聪明得多,并且完全能够缓存映射的内容。哎呀,如果您将其映射为只读,那么与直接从程序的基本映像访问数据将没有什么区别。
[1]:这适用于 WIndows 和 Unix
Are you re-inventing
I also think you're might be optimizing the wrong things.
The kernel[1] is way smarter than we are and is perfectly capable of caching the mapped stuff. Heck, if you map it READ-ONLY there will be no difference with directly accessing data from your program's base image.
[1]: this goes for both WIndows and Unix