delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/02/11/13:38:07

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f
From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10202111838.AA23830@clio.rice.edu>
Subject: Re: Alignment problem
To: djgpp-workers AT delorie DOT com
Date: Mon, 11 Feb 2002 12:38:13 -0600 (CST)
Cc: rudd AT cyberoptics DOT com
In-Reply-To: <3C6803E2.38801604@cyberoptics.com> from "Eric Rudd" at Feb 11, 2002 11:48:18 AM
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> it appears as the alignment of malloc() follows the alignment of sbrk().

Yes, exactly correct.  

> Is sbrk() supposed to return aligned pointers?  If not, then malloc needs to
> deal with the misalignment.

sbrk() is not supposed to provide any alignment.

malloc() ideally should deal with the misalignment since user applications
might call sbrk() and screw up the alignment.

If we wanted to ignore the user screwed us up issue, then we could 
investigate making sure that at least the first sbrk() returns aligned
memory and then the library always makes sbrk() requests in 8 byte 
increments.  This might be tough, since the user can specify the stack
size (sbrk'ed) as is the stubinfo.

> I'll take a look at the code.  If I get in over my head, I'll ask for help.
> Perhaps the first thing I should do is to figure out the format of the block
> headers.  Does anyone know what this is?

I took a quick look at fixing this.  We should only have problems when
sbrk() is not what is expected - which is pretty well documented in the
code.  If it returns an address which isn't aligned it gets a bit ugly.
I suggest we sbrk() another 1-7 bytes at that point hoping it will be 
contig at the end of the current allocation.  This should usually work.
When it doesn't is what's tricky - but maybe we just give up and return
the unaligned buffer.  Or negative sbrk() the memory back.  or whatever.

So, bug me if you get stuck.

One reason I think this is worth fixing is the reproducibility issue.
An application runs in 10 seconds.  You run it again and it take 7 
seconds.  Then 10 seconds.  All depending on what random alignment that
windows provided.  Or you get different speeds on different platforms
that are alignment based, but you don't know it.

(I see it as a right thing to do issue more than a standards issue).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019