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 293541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:17:06+00:00 2026-05-12T06:17:06+00:00

I have an array, called x, whose size is 6*sizeof(float). I’m aware that declaring:

  • 0

I have an array, called x, whose size is 6*sizeof(float). I’m aware that declaring:

float x[6];

would allocate 6*sizeof(float) for x in the stack memory. However, if I do the following:

float *x;   // in class definition

x = new float[6];   // in class constructor

delete [] x;    // in class destructor

I would be allocating dynamic memory of 6*sizeof(float) to x. If the size of x does not change for the lifetime of the class, in terms of best practices for cleanliness and speed (I do vaguely recall, if not correctly, that stack memory operations are faster than dynamic memory operations), should I make sure that x is statically rather than dynamically allocated memory? Thanks in advance.

  • 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-12T06:17:06+00:00Added an answer on May 12, 2026 at 6:17 am

    Declaring the array of fixed size will surely be faster. Each separate dynamic allocation requires finding an unoccupied block and that’s not very fast.

    So if you really care about speed (have profiled) the rule is if you don’t need dynamic allocation – don’t use it. If you need it – think twice on how much to allocate since reallocating is not very fast too.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Short answer: Yes. Long answer: Not really an "optimization", as… May 12, 2026 at 8:12 pm
  • Editorial Team
    Editorial Team added an answer The difference is the URL generated. Let's guess three resources… May 12, 2026 at 8:12 pm
  • Editorial Team
    Editorial Team added an answer No idea what you mean about "the color that highlights… May 12, 2026 at 8:12 pm

Related Questions

I have an array, called x, whose size is 6*sizeof(float). I'm aware that declaring:
I have an array of values called A, B... X, Y, Z. Fun though
I have an array an a timer that adds a new object to my
I have a couple of classes that want to pass each other some information
I am writing a program that will draw a solid along the curve 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.