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 26 of 32 Topic 26155 of 27670
Post > Topic >>

Re: standard memory allocator alignment issue...

by Ben Bacarisse <ben.usenet@[EMAIL PROTECTED] > May 13, 2008 at 03:36 AM

"Chris Thomasson" <cristom@[EMAIL PROTECTED]
> writes:

> "Ben Bacarisse" <ben.usenet@[EMAIL PROTECTED]
> wrote in message
> news:877idz81nm.fsf@[EMAIL PROTECTED]
>
> [...]
>> 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 po[r]table way.
<snip, but permit me to correct my typo!>
>
> I am currently using something like the following hack to align
> pointers on boundaries which are powers of 2:
<snip>
> typedef long int align_detail_intptr;
<snip>
> #define ALIGN_POW2(mp_this, mp_type) ((mp_type)( \
>  (((align_detail_intptr const)(mp_this)) + 1) & (-2) \
> ))
>
>
> #define ALIGN(mp_this, mp_type, mp_align) ((mp_type)( \
>  (((align_detail_intptr const)(mp_this)) + \
>   ALIGN_POW2(mp_align, align_detail_intptr const) - 1) \
>  & (-ALIGN_POW2(mp_align, align_detail_intptr const)) \
> ))
<snip>
> Any suggestions on how to improve the abomination?
>
> ;^)

I would do***ent (maybe another clause in your static assert?) that
long must be able to hold a pointer (I assume you can't use C99's
intptr_t?).

You rely on the representation of -2 and of -ALIGN_POW2(...).  I'd use
all unsigned types to avoid both.  Other than that, I think this is
the best you can do (but I am no expert on this so you may well get
better advice shortly...).

-- 
Ben.
 




 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 Oct 10 22:15:28 CDT 2008.