comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Y21C Bug
Date: 2000/01/07
Date: 2000-01-07T00:00:00+00:00	[thread overview]
Message-ID: <wcciu157w2h.fsf@world.std.com> (raw)
In-Reply-To: 87iu16yxv4.fsf@deneb.cygnus.argh.org

Florian Weimer <usenet@deneb.cygnus.argh.org> writes:

> I think commit on use is the same thing what's called copy on write
> on Linux.

Really?  I thought "copy on write" (or "virtual copy") meant what, for
example, most modern Unix systems do for fork() -- the fork() system
call is defined to copy the entire address space of the process,
producing two identical processes.  Using memory-mapping hardware, you
can map all the pages to the same physical locations, and mark them
read-only.  If either process actually wants to write, it traps into the
OS, which actually makes the copy.

I thought "commit on use" (or "zero on use") meant that (as in your
example below), virtual memory is allocated, but physical memory is not.
Then, a read or write of that memory will trap, and the operating system
will gin up an all-zeros page of memory.

Still nobody has answered my question about which operating systems
support these fancy things.

>  For example, you can run the following program on a box
> which only has some 300 MB of virtual memory (RAM + swap), and it will
> `allocate' approximately 1.5 GB of `memory':
[program that allocates large numbers of huge strings]

> Of course, you shouldn't use an initialized allocator here. ;)

Indeed.

I once wrote a program that was doing something like that for
arrays-of-pointers-to-records.  I might allocate millions of pointers,
and only use 3 or 4 of them in a typical case, but once in a while need
a whole lot.  Unfortunately, Ada wants to initialize pointers to null,
which caused my program to run extremely slowly -- it spent most of its
time initializing data that I was never going to use in the typical case
(and probably paging it out disk for me, too -- I don't remember).

I solved the problem with an ugly hack: allocate an array of integers,
and unchecked-convert to an array of pointers.  Or maybe I
unchecked-converted a pointer to the arrays -- I don't remember.

I think the DEC Ada compiler would have handled it better -- I think it
was clever enough to know that the VMS operating system was going to
zero those pages if they were ever referenced, and null is represented
as zero, so the compiler didn't actually zero them.

On the other hand, I once wrote something like:

    X: array(1..One_Zillion) of Integer := (others => 0);

and the DEC Ada compiler blew up at compile time, apparently trying to
be clever at run time.

Anyway, none of these fancy memory-mapping tricks are much good if
they're not portable.

- Bob




  reply	other threads:[~2000-01-07  0:00 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-02  0:00 Y21C Bug reason67
2000-01-02  0:00 ` Robert Dewar
2000-01-03  0:00   ` Tarjei T. Jensen
2000-01-03  0:00     ` Jeff Creem
2000-01-03  0:00       ` Tarjei T. Jensen
2000-01-03  0:00     ` Robert A Duff
2000-01-04  0:00       ` Tarjei T. Jensen
2000-01-04  0:00         ` Robert A Duff
2000-01-04  0:00         ` Samuel Tardieu
2000-01-04  0:00         ` Robert Dewar
2000-01-05  0:00           ` Tarjei T. Jensen
2000-01-05  0:00             ` Al Christians
2000-01-06  0:00               ` Tarjei T. Jensen
2000-01-06  0:00                 ` Robert Dewar
2000-01-06  0:00                   ` Robert A Duff
2000-01-06  0:00                     ` Larry Kilgallen
2000-01-07  0:00                     ` Florian Weimer
2000-01-07  0:00                       ` Robert A Duff [this message]
2000-01-07  0:00                         ` Robert Dewar
2000-02-04  0:00                           ` Florian Weimer
2000-02-04  0:00                             ` Robert A Duff
2000-02-04  0:00                               ` Florian Weimer
2000-01-11  0:00                         ` Mats Weber
2000-01-11  0:00                           ` Robert A Duff
2000-01-12  0:00                             ` Mats Weber
2000-01-12  0:00                               ` Thierry Lelegard
2000-01-13  0:00                                 ` Mats Weber
2000-01-13  0:00                                 ` Robert A Duff
2000-01-13  0:00                                   ` Larry Kilgallen
2000-01-13  0:00                                   ` Thierry Lelegard
     [not found]                               ` <387dfb1e.cbbf14c7@mail.com>
2000-01-13  0:00                                 ` Larry Kilgallen
2000-01-11  0:00                     ` Mats Weber
2000-01-07  0:00                   ` Tarjei T. Jensen
2000-01-07  0:00                     ` Robert Dewar
2000-01-06  0:00               ` Robert Dewar
2000-01-05  0:00             ` Robert Dewar
2000-01-06  0:00               ` Tarjei T. Jensen
2000-01-06  0:00                 ` Larry Kilgallen
2000-01-06  0:00               ` Richard D Riehle
2000-01-06  0:00               ` Georg Bauhaus
2000-01-06  0:00                 ` Tarjei T. Jensen
2000-01-04  0:00       ` Robert Dewar
2000-01-04  0:00         ` Charles Hixson
2000-01-04  0:00           ` Keith Thompson
2000-01-05  0:00           ` Robert Dewar
2000-01-05  0:00           ` Robert Dewar
2000-01-05  0:00             ` Y21C Bug :-) Charles Hixson
2000-01-06  0:00               ` Ted Dennison
2000-01-07  0:00                 ` Keith Thompson
2000-01-07  0:00                   ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox