简体   繁体   中英

How can I tell a Linux process to use a file as its entire heap?

Say I have a 10MB file on my hard drive. Say I also have a C program and it mallocs a bunch of data and sets various bytes. Is it possible for me to tell this program to target this file as though it were the only memory available on the system, thus redirecting malloc calls to allocate from the 10MB file instead of my system's real memory?

It's not straightforwardly possible to redirect all memory allocation to a mapped file, without editing glibc. However, there is dmalloc , which allows you to use a differently named but equivalent function to allocate from a file. (You could just #define malloc dmalloc , but that wouldn't affect libraries, and could screw up other headers.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM