comp.lang.ada
 help / color / mirror / Atom feed
From: gisle@apal.ii.uib.no (Gisle Sælensminde)
Subject: Re: Counting Elements figured out.
Date: 03 Dec 2005 23:04:41 +0100
Date: 2005-12-03T22:04:41+00:00	[thread overview]
Message-ID: <0n3bl9hm6e.fsf@apal.ii.uib.no> (raw)
In-Reply-To: wcc3blbt7sp.fsf@shell01.TheWorld.com

Robert A Duff <bobduff@shell01.TheWorld.com> writes:

> Freejack <freejack@nowhere.net> writes:
> 
> > Aha. I gotcha. I suppose I should take that into account when mapping the
> > storage space into my process. I just tested it out. It works when the
> > compiler does it's malloc() allocations, but segfaults on an mmaped()
> > region. So the length of the region I map should be
> > Size_In_Storage_Elements + 1, yes? And then use the " - 1 " on allocations
> > from that region?

I would think that allocation Size_In_Storage_Elements + 1 will give one
byte to much for the underlying file (unless it's an annonymous map). Then
mmap will return without error, but the process will be recieve a bus error
if the last byte is accessed. 

> I don't really understand the above, but it doesn't look right.
> 
> Anyway, mmap requires page-alignment, right?  That is, you can't mmap
> 100 bytes; you have to round it up to 2**12 or 2**13 bytes or some
> such.

The mmap call will allocate in blocks, but it will always allocate at least
as much as you ask for, so it's no problem to map 100 bytes with mmap.
It is more likely that the OP did not set the mapped pages to be readable or
writable, or that the file was actually shorter than the number of bytes 
asked for. This (and more) will cause mmap to return "successfully", but 
the process will fail when the memory is accesed. It's far fewer things 
that can go wrong with malloc. In fact malloc may also have this 
blockwise allocation property on many systems.

-- 
Gisle Sælensminde, Phd student, Scientific programmer
Computational biology unit, BCCS, University of Bergen, Norway, 
Email: gisle@cbu.uib.no




  reply	other threads:[~2005-12-03 22:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <pan.2005.11.30.01.47.41.83657@nowhere.net>
2005-11-25 16:29 ` Counting Elements figured out David C. Hoos, Sr.
     [not found]   ` <pan.2005.11.30.23.15.25.917461@nowhere.net>
2005-12-02 23:09     ` Robert A Duff
2005-12-03 22:04       ` Gisle Sælensminde [this message]
2005-12-03 22:21         ` 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