From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2808111f01d47bd3 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!uio.no!nntp.uib.no!not-for-mail From: gisle@apal.ii.uib.no (=?utf-8?b?R2lzbGUgU8ODwqZsZW5zbWk=?= =?utf-8?b?bmRl?=) Newsgroups: comp.lang.ada Subject: Re: Counting Elements figured out. Date: 03 Dec 2005 23:04:41 +0100 Organization: University of Bergen Message-ID: <0n3bl9hm6e.fsf@apal.ii.uib.no> References: NNTP-Posting-Host: apal.ii.uib.no Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: toralf.uib.no 1133647481 76407 129.177.16.81 (3 Dec 2005 22:04:41 GMT) X-Complaints-To: abuse@uib.no NNTP-Posting-Date: 3 Dec 2005 22:04:41 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: g2news1.google.com comp.lang.ada:6731 Date: 2005-12-03T22:04:41+00:00 List-Id: Robert A Duff writes: > Freejack 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