Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: standard me...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 22 of 32 Topic 26173 of 26972
Post > Topic >>

Re: standard memory allocator alignment issue...

by Keith Thompson <kst-u@[EMAIL PROTECTED] > May 13, 2008 at 09:23 AM

Ben Bacarisse <ben.usenet@[EMAIL PROTECTED]
> writes:
> Keith Thompson <kst-u@[EMAIL PROTECTED]
> writes:
>> Spiros Bousbouras <spibou@[EMAIL PROTECTED]
> writes:
[...]
>>> If you had ALIGN_MAX what would you do with it ?
>>
>> One thing I might do is write my own memory allocator.  Call malloc()
>> once to get a big chunk of memory (guaranteed to be aligned properly),
>> then dole out properly-aligned subchunks of it in response to
>> my_malloc() calls.  Free everything at once by free()ing the big
>> chunk.  Without ALIGN_MAX, I can't think of a ****table way to
>> guarantee that the pointers returned by my_malloc are properly
>> aligned.
>
> The suggestion seems to be that ALIGN_MAX is some arithmetic value.  I
> can't see a way to adjust a pointer using it in any potable way.  I
> think this is the point behind Eric's "Without knowledge of which
> integer bits have what significance, you can't make effective use of
> things like ALIGN_MAX".  The standard declines to say anything about
> what the arithmetic value of a well-aligned pointer is.

Agreed.  An ALIGN_MAX constant (which might typically be 8 on modern
systems) is useful only if you start with an address that you already
know is adequately aligned -- which is why I started with malloc().
It's not enough to let you write a ****table malloc()-like function
from scratch.

> If you are assuming that the suggestion is for a function-line macro:
>
> #define ALIGN_MAX(p)
>
> that behaves like a function declared void *ALIGN_MAX(void *) which
> adjusts the pointer it is given, then I agree it would be possible to
> write an allocator.  (But I would suggest the name be lower-cased to
> match things like offsetof and changed to sound less like a constant
> -- another parameter might also be required to indicate "direction").

Or you could have, say an alignment_offset(p) macro which, given a
char* value, gives you a small integer value you can add to it to
yield a pointer that's guaranteed to be adequately aligned.

-- 
Keith Thompson (The_Other_Keith) kst-u@[EMAIL PROTECTED]
 
<http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
 




 32 Posts in Topic:
standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-11 23:13:16 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-11 23:24:31 
Re: standard memory allocator alignment issue...
Eric Sosman <esosman@[  2008-05-12 08:14:40 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 14:41:20 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 14:51:41 
Re: standard memory allocator alignment issue...
Eric Sosman <Eric.Sosm  2008-05-12 18:22:03 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 15:41:29 
Re: standard memory allocator alignment issue...
Ian Collins <ian-news@  2008-05-13 11:22:53 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 16:36:44 
Re: standard memory allocator alignment issue...
Eric Sosman <Eric.Sosm  2008-05-12 18:08:39 
Re: standard memory allocator alignment issue...
Ian Collins <ian-news@  2008-05-13 11:32:26 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 16:41:37 
Re: standard memory allocator alignment issue...
Ian Collins <ian-news@  2008-05-13 11:56:18 
Re: standard memory allocator alignment issue...
Spiros Bousbouras <spi  2008-05-12 16:02:41 
Re: standard memory allocator alignment issue...
richard@[EMAIL PROTECTED]  2008-05-12 23:13:30 
Re: standard memory allocator alignment issue...
Keith Thompson <kst-u@  2008-05-12 16:20:39 
Re: standard memory allocator alignment issue...
Chris Torek <nospam@[E  2008-05-13 00:46:18 
Re: standard memory allocator alignment issue...
Keith Thompson <kst-u@  2008-05-13 00:46:55 
Re: standard memory allocator alignment issue...
Ben Bacarisse <ben.use  2008-05-13 01:53:49 
Re: standard memory allocator alignment issue...
Eric Sosman <esosman@[  2008-05-12 21:26:56 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-12 19:00:01 
Re: standard memory allocator alignment issue...
Keith Thompson <kst-u@  2008-05-13 09:23:10 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-28 23:57:44 
Re: standard memory allocator alignment issue...
"Chris Thomasson&quo  2008-05-29 00:02:17 
Re: standard memory allocator alignment issue...
Ben Bacarisse <ben.use  2008-05-13 03:07:49 
Re: standard memory allocator alignment issue...
Ben Bacarisse <ben.use  2008-05-13 03:36:49 
Re: standard memory allocator alignment issue...
Spiros Bousbouras <spi  2008-05-13 10:53:22 
Re: standard memory allocator alignment issue...
Eric Sosman <Eric.Sosm  2008-05-13 14:26:59 
Re: standard memory allocator alignment issue...
Keith Thompson <kst-u@  2008-05-13 12:32:07 
Re: standard memory allocator alignment issue...
CBFalconer <cbfalconer  2008-05-13 16:24:00 
[OT] Re: standard memory allocator alignment issue...
Eric Sosman <Eric.Sosm  2008-05-13 17:11:24 
Re: [OT] Re: standard memory allocator alignment issue...
Richard Heathfield <rj  2008-05-13 22:07:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:41:49 CDT 2008.