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 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 118k
  • Answers 118k
  • 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 You can do that. The problem is the inheritance modifier… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer Assuming your controller class derives from System.Web.Mvc.Controller (probably this is… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer It's because the this scope refers to a cfc instance.… May 11, 2026 at 11:32 pm

Related Questions

Most of experienced programmer knows data alignment is important for program's performance. I have
What is a fast and efficient way to implement the server-side component for an
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 find the nature of this question to be quite suited for the practical-minded

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.