Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 500193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:03:44+00:00 2026-05-13T06:03:44+00:00

In K&R2 they implement memory allocator in chapter 8. For each block there is

  • 0

In K&R2 they implement memory allocator in chapter 8. For each block there is header defined something like this (from memory, code may be non-exact):

union header_t
{
  struct 
  {
     unsigned size;
     unsigned* next; 
  };

  long align;
};

They do this to “make sure that the header is properly aligned on the boundaries of long”. But doesn’t the union align by the largest member? The struct is larger than the single align member, so the header will be aligned on the struct’s multiples anyway, no?

What about when the struct is even larger (say it has many members). Is this alignment union trick always required in when write a memory allocator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:03:44+00:00Added an answer on May 13, 2026 at 6:03 am

    “The struct is larger than the single align member”.

    First, says who? What if, on your implementation, unsigned and unsigned* are each 32 bits, and long is 128 bits (or more realistically, 16 bits and 64 bits)?

    Second, so what? Even if the struct is at least as big as long, it doesn’t mean that it must have at least as big an alignment as long. If unsigned and unsigned* have no alignment requirements, then the struct has no alignment requirements. But perhaps long does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did mockups in balsamiq & they have this nice widget, which Allowed to
Sometimes users mistakenly redirected to ?Process=ViewImages&PAGEID=. When this happens, they get the following error.
I am looking to implement something similar to facebook/gmail chat. I know they use
I'm using JQuery to find certain div classes within DOM & If they found
So recently i was thinking about strcpy and back to K&R where they show
I've got a screen that allows users to add & remove rows which they'll
I am getting stuck in a page,where I'm using selectbox & checkbox,and they will
Facebook allows a distance parameter for their search like https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000 They don't say what
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I've been trying to implement NSXMLParser and so far I've had memory issues, performance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.