A debugging implementation of malloc

D

Dann Corbit

Chris said:
Barry Schwarz wrote:
At this point [where r is the result of a malloc() call] r contains
the address of a block of memory properly aligned for any possible
object.

Is there a portable way of finding out what this alignment is?

No. I consider this a flaw in the C standards.

If there *were* a portable way to find this, you could write portable
"augmented malloc and free" routines along the lines of those Mr Navia
has provided (with more work to deal with alignment, of course). ...

I think you mean to add a qualifier that pointers
can be turned into integers and operated on sensibly.
Otherwise knowing the alignment doesn't help.

Dumb question:

If we have no guarantee of modular math on the pointers, then why not
repeated subtraction on the pointers (which is clearly guaranteed)?
 
E

ena8t8si

Dann said:
Chris said:
Barry Schwarz wrote:
At this point [where r is the result of a malloc() call] r contains
the address of a block of memory properly aligned for any possible
object.

Is there a portable way of finding out what this alignment is?

No. I consider this a flaw in the C standards.

If there *were* a portable way to find this, you could write portable
"augmented malloc and free" routines along the lines of those Mr Navia
has provided (with more work to deal with alignment, of course). ...

I think you mean to add a qualifier that pointers
can be turned into integers and operated on sensibly.
Otherwise knowing the alignment doesn't help.

Dumb question:

If we have no guarantee of modular math on the pointers, then why not
repeated subtraction on the pointers (which is clearly guaranteed)?

Subtraction on pointers means you have a base
pointer to start with. I took the comment to
mean that finding the initial base pointer is
what we're looking for. Can't do subtraction
if there's no base to subtract.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top