start partial binary

Adam D. Ruppe destructionator at gmail.com
Wed Mar 12 18:25:12 PDT 2008


On Thu, Mar 13, 2008 at 12:44:46AM +0000, Sean Kelly wrote:
> Does the full binary of an application get loaded when the app executes?
> I was under the assumption that code pages were loaded as needed.
>
> Sean

Yes, it looks like you're right according to a web search. So it should
be possible on Linux - using import()'s seems to me that it would be
the easiest way.

How it might be done in D:

-------------

import std.stdio;
string hugeFile = import("hugefile.txt");
	// If a reader is new to D, the above loads "hugefile.txt" at compile
	// time, as if I wrote:
	// string hugeFile = "the literal contents of hugefile.txt here";

void main(){
	writefln("...");
	readln();
	writefln("%s", hugeFile);
}

-------------

And to see how it works, watch for disk activity before and after the readln.
But, I'm foiled in testing the efficiency of this on the disk by the fact that
when making the executable, Linux caches the whole thing in RAM, so it doesn't
need to hit the disk anyway.

Note that the import used there doesn't work for absolutely huge files. It
works for anything less than at least 5 MB though, and probably more, which
might be enough to do the job wanted.

It's worth a try.

-- 
Adam D. Ruppe
http://arsdnet.net



More information about the Digitalmars-d mailing list