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 16 of 32 Topic 26155 of 27678
Post > Topic >>

Re: standard memory allocator alignment issue...

by Keith Thompson <kst-u@[EMAIL PROTECTED] > May 12, 2008 at 04:20 PM

Spiros Bousbouras <spibou@[EMAIL PROTECTED]
> writes:
> On 12 May, 23:41, "Chris Thomasson" <cris...@[EMAIL PROTECTED]
> wrote:
>> "Eric Sosman" <Eric.Sos...@[EMAIL PROTECTED]
> wrote in message
>>
>> news:1210630927.374478@[EMAIL PROTECTED]
>>
>> > Chris Thomasson wrote:
>> >> [... determining alignment with a struct and offsetof ...]
>>
>> >> I have been successfully using the previous method in several
>> >> general-purpose memory allocators. However, I wanted to see if there
is a
>> >> better way; offsetof works fine. BTW, does anybody know why there is
not
>> >> something like ALIGN_MAX in <limits.h> already?
>>
>> >     The Rationale doesn't say why not.  My guess (and it's only
>> > a guess) is that the Committee didn't want to get too involved
>> > in specifying exactly how pointers convert to and from integers.
>> > Without knowledge of which integer bits have what significance,
>> > you can't make effective use of things like ALIGN_MAX.
>>
>> Humm, a compiler vendor already has to supply a malloc implementation
which
>> returns an address that is aligned on a sufficient boundary for all
integral
>> types; right? Well, IMVHO, the standard could mention that a vendor
shall
>> set the value of ALIGN_MAX to a sufficient boundary analogous to the
>> non-NULL return value of malloc which can accompany the alignment of
any
>> integral type. The rational is that a vendor can likely extract
ALIGN_MAX
>> from their existing malloc implementation...
>
> 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.

-- 
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 Sat Oct 11 18:38:02 CDT 2008.