Date: Thu, 15 Jan 1998 23:12:12 -0200 (EDT) From: Joao Carlos Mendes Luis <jonny@coppe.ufrj.br> To: joelh@gnu.org Cc: atrens@nortel.ca, freebsd-hackers@FreeBSD.ORG Subject: Re: sharable static arrays? Message-ID: <199801160112.XAA01058@gaia.coppe.ufrj.br> In-Reply-To: <199801151908.NAA01914@detlev.UUCP> from Joel Ray Holveck at "Jan 15, 98 01:08:20 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
#define quoting(Joel Ray Holveck)
// > Copy-on-write aka `lazy copy' is a detail of the implementation
// > *not* the interface. You must assume that each process gets its own
// > data segment, period. Otherwise you couple your code to the OS
// > implementation. There are a number of reasons why this a bad idea.
//
// I realize that I can't depend on details of the OS implementation,
// particularly since copy-on-write is transparent to the user. However,
// when I'm writing a program and trying to decide whether a large lookup
// table should be built statically into the compiled code, generated at
// runtime, or whatever, it is helpful to know how the memory usage will
// be affected. That's what I'm trying to accomplish with this whole
// issue.
Why don't you simply save all your huge const data array in a separate
file, and mmap() it in ?
The compiler will also be happy with this approach, not having to compile
this huge array all time.
const bigtype *bigarray;
int fd;
struct stat si;
...
if ( ( fd = open( BIGFILE, O_RDONLY ) ) < 0 ) {
printf( "Error opening data file !!!" );
return;
}
fstat( fd, &si );
if ( ( bigarray = mmap( NULL, si.st_size, PROT_READ, MAP_INHERIT, fd, 0 ) ) < 0 ) {
printf( "Error mmaping file" );
return;
}
...
Jonny
--
Joao Carlos Mendes Luis jonny@gta.ufrj.br
+55 21 290-4698 jonny@coppe.ufrj.br
Universidade Federal do Rio de Janeiro UFRJ/COPPE/CISI
PGP fingerprint: 29 C0 50 B9 B6 3E 58 F2 83 5F E3 26 BF 0F EA 67
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801160112.XAA01058>
