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

  • Home
  • SEARCH
  • 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 122607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:09:20+00:00 2026-05-11T04:09:20+00:00

Most of experienced programmer knows data alignment is important for program’s performance. I have

  • 0

Most of experienced programmer knows data alignment is important for program’s performance. I have seen some programmer wrote program that allocate bigger size of buffer than they need, and use the aligned pointer as begin. I am wondering should I do that in my program, I have no idea is there any guarantee of alignment of address returned by C++’s new operation. So I wrote a little program to test

for(size_t i = 0; i < 100; ++i) {     char *p = new char[123];     if(reinterpret_cast<size_t>(p) % 4) {         cout << '*';         system('pause');     }     cout << reinterpret_cast<void *>(p) << endl; } for(size_t i = 0; i < 100; ++i) {     short *p = new short[123];     if(reinterpret_cast<size_t>(p) % 4) {         cout << '*';         system('pause');     }     cout << reinterpret_cast<void *>(p) << endl; } for(size_t i = 0; i < 100; ++i) {     float *p = new float[123];     if(reinterpret_cast<size_t>(p) % 4) {         cout << '*';         system('pause');     }     cout << reinterpret_cast<void *>(p) << endl; } system('pause'); 

The compiler I am using is Visual C++ Express 2008. It seems that all addresses the new operation returned are aligned. But I am not sure. So my question is: are there any guarantee? If they do have guarantee, I don’t have to align myself, if not, I have to.

  • 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. 2026-05-11T04:09:20+00:00Added an answer on May 11, 2026 at 4:09 am

    The alignment has the following guarantee from the standard (3.7.3.1/2):

    The pointer returned shall be suitably aligned so that it can be converted to a pointer of any complete object type and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function).

    EDIT: Thanks to timday for highlighting a bug in gcc/glibc where the guarantee does not hold.

    EDIT 2: Ben’s comment highlights an intersting edge case. The requirements on the allocation routines are for those provided by the standard only. If the application has it’s own version, then there’s no such guarantee on the result.

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Actually, CollabNet has the original source code of subversion. Check… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer If you look at the page using the sharepoint designer… May 11, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer An event doesn't expose the field and its value -… May 11, 2026 at 5:59 pm

Related Questions

Most of experienced programmer knows data alignment is important for program's performance. I have
Summary: Can I program a thick client game in C without reinventing wheels ,
What is most important at this time? I know that I can acquire programming
I am not the most experienced GUI programmer, so bear with me here. I
Which class hierarchy is most necessary in order to get an excellent grasp of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.