Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read data in executable on run

Tags:

c++

c

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:

  1. 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.
  2. Using shared memory with another process (something like server, which holds data) is not cross-compiling
  3. 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!

like image 716
serenheit Avatar asked Mar 15 '26 17:03

serenheit


1 Answers

Are you re-inventing

  • exe packers (see http://en.wikipedia.org/wiki/Executable_compression)
  • embedded resources? A portable approach was described here Is there any standard way of embedding resources into Linux executable image?

I also think you're might be optimizing the wrong things.

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.

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

like image 57
sehe Avatar answered Mar 17 '26 08:03

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!