Re: [PATCH 2/2] Use fixed-size integers for .idx file I/O
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 18, 2007, 15:30 UTC
- Message-ID
- <Pine.LNX.4.63.0701181630070.22628@wbgn013.biozentrum.uni-wuerzburg.de>
- In-Reply-To
- <20070118152107.GA15428@spearce.org>
Hi,
On Thu, 18 Jan 2007, Shawn O. Pearce wrote:
Show 22 quoted lines
> Simon 'corecode' Schubert <corecode@fs.ei.tum.de> wrote: > > Morten Welinder wrote: > > >>- return ntohl(*((unsigned int *) ((char *) > > >>index + (24 * mi)))); > > >>+ return ntohl(*((uint32_t *)((char *)index + > > >>(24 * mi)))); > > > > > >Is that pointer gymnastics guaranteed to work? I.e., how do we know > > >that we can access an uint32_t (or unsigned) at such an address? > > > > if index is always aligned to a 4-byte boundary, this is safe. apart from > > that, the problem already existed. > > Its always 4-byte aligned here. The index is mmap()'d as one huge > chunk so the first byte of the index is page aligned. The index > starts out with 256 4-byte words, then is composed of 24 byte units > (20 byte SHA1, 4 byte offset). So no worries with the current file > format, or code. > > Yes, we're taking the leap of faith that any currently-used processor > will work on 32 bit unsigned integers if they are 4 byte aligned in > memory.
Actually, it's even valid in 8 byte aligned mode. (24 is divisible by 8.)
Ciao, Dscho