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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:42:53+00:00 2026-05-15T01:42:53+00:00

If i use auto_ptr to hold a pointer to a dynamically allocated array, when

  • 0

If i use auto_ptr to hold a pointer to a dynamically allocated array, when the auto_ptr gets killed it will use a plain delete operation and not delete[] thus not deleting my allocated array.

How can i (properly) use auto_ptr on dynamically allocated arrays?

If this is not possible, is there another smart pointer alternative for dynamically allocated arrays?

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-15T01:42:54+00:00Added an answer on May 15, 2026 at 1:42 am

    boost::shared_array is what your looking for.

    EDIT:

    If you want to avoid the use of boost I would recommend just using std::vector they are array’s underneath and there is no need to worry about memory allocation. Actually this is a better solution than shared_array anyway.

    Since you indicate that you wanted to use auto_ptr then you don’t need the reference counting and ownership model of shared_array. So just use a std::vector as they are tailored to replace dynamically allocated arrays which is really what you are trying to manage with the use of auto_ptr.

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

Sidebar

Related Questions

I'd need a class like std::auto_ptr for an array of unsigned char*, allocated with
Do anyone know any way to use smart_ptr (Smart Pointer) or auto_ptr (Auto Pointer)
Possible Duplicate: Which kind of pointer do I use when? I read that std::auto_ptr
I didn't find information about performance issues with auto_ptr and shared_ptr (I use tr1
I'm trying to use smart pointers such as auto_ptr, shared_ptr. However, I don't know
std::auto_ptr is not allowed to be stored in an STL container, such as std::vector
I know that I am supposed to use delete [] after I use new
When trying to use an auto_ptr with a type that was declared with forward-declaration,
std::auto_ptr is broken in VC++ 8 (which is what we use at work). My
So what happens to a pointer if you release an object owned by auto_ptr

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.