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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:25:03+00:00 2026-05-23T14:25:03+00:00

I just want to make sure there aren’t any potential problems with this. It

  • 0

I just want to make sure there aren’t any potential problems with this. It compiles and runs fine, but am I risking any weird memory effects? Do I need to be especially concerned about exceptions in this case?

//...constructor of some class
myobj(int length, int *vars)
{
    // do stuff with vars
}

// inside some other code somewhere
int vars[3] = {5,6,7};
myobj *o = new myobj(3,vars);

(Edit.) I’m just concerned because I know pointers to objects on the stack should always be used with caution. To be specific about my usage, I’d mainly like the fastest way to pass in a variable number of arguments of the same type. So is this a bad way to do it? Thanks..

Postscript. All the answers were very helpful, thanks! I’ll see whether the performance matters enough to use this method, or perhaps if I can solve the problem another way altogether.

  • 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-23T14:25:04+00:00Added an answer on May 23, 2026 at 2:25 pm

    There’s nothing inherently wrong with this. However, there are a few things you need to be careful of:

    • Don’t keep a pointer to vars around after you return (or at least, after it goes out of scope). vars is only valid until you leave the scope that it was declared in.
    • Make sure you don’t run off the end of the vars array.

    It’s more common style in C++ to use, e.g. a std::vector<int> & parameter, or some other container type. This has two major reasons for it: By passing as a reference, it makes it more obvious that you may not be meant to keep a pointer to the object, and by passing a vector, the size of the array is kept along with the array itself (and you can expand the array if need be as well). However, this is a matter of style, and there is overhead to vector, so if performance is at a premium, this approach is perfectly reasonable.

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

Sidebar

Related Questions

I think that I fully understand this, but I just want to make sure
Just wondering if you had any thoughts on this problem. I want to make
I just want to make sure if I am doing this correct. I am
Just want to make sure this is the best way to call a connection,
Just want to make sure I understand this correctly (I'd ask on SO Chat,
Hi I just want to make sure I have these concepts right. Overloading in
I am doing a md5 hash, and just want to make sure the result
I can't seem to find an answer on this and just want to make
Just want to make sure my test code below is proper. I've been reading
I just want to make sure I got the idea of public and private

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.