From owner-freebsd-hackers Thu Jan 15 17:12:39 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA05863 for hackers-outgoing; Thu, 15 Jan 1998 17:12:39 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from gaia.coppe.ufrj.br (cisigw.coppe.ufrj.br [146.164.5.200]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA05812 for ; Thu, 15 Jan 1998 17:12:30 -0800 (PST) (envelope-from jonny@coppe.ufrj.br) Received: (from jonny@localhost) by gaia.coppe.ufrj.br (8.8.8/8.8.8) id XAA01058; Thu, 15 Jan 1998 23:12:13 -0200 (EDT) (envelope-from jonny) From: Joao Carlos Mendes Luis Message-Id: <199801160112.XAA01058@gaia.coppe.ufrj.br> Subject: Re: sharable static arrays? In-Reply-To: <199801151908.NAA01914@detlev.UUCP> from Joel Ray Holveck at "Jan 15, 98 01:08:20 pm" To: joelh@gnu.org Date: Thu, 15 Jan 1998 23:12:12 -0200 (EDT) Cc: atrens@nortel.ca, freebsd-hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL32 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk #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