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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:59:59+00:00 2026-06-09T01:59:59+00:00

Normally when I use STL objects that are in a non-local scope I store

  • 0

Normally when I use STL objects that are in a non-local scope I store pointers to the data I want to store. For instance

std::vector<MyStruct*> 

When it’s time to cleanup the vector I then go through and delete everything. I’ve recently noticed that this isn’t necessary like I thought it was. For whatever reason I was thinking the STL classes stored data on the stack, whereas I now think it allocates it on the heap. Is this correct? Is the only real benefit to storing objects as pointers to reduce copy time?

  • 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-06-09T02:00:01+00:00Added an answer on June 9, 2026 at 2:00 am

    The standard containers allocate memory via an Allocator object, whose type is passed as a template parameter. If you’re not passing anything else, that’ll be std::allocator<T>, which will use new to allocate the memory.

    Bottom line: you can force them to allocate memory almost any way you want to, but by default it’ll come from the free store.

    If you really want a container of pointers were the container will own the pointee objects, (e.g., will automatically delete them when the object is destroyed), you might want to look at Boost Pointer Containers.

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

Sidebar

Related Questions

I have this code that where I would normally use one line: if (tableView
I want to detect when my touchpad is clicked! I normally use a usb
I was wondering, I normally use std::string for my code, but when you are
Web services on Heroku normally use the PORT environment variable, but I want to
What is difference between our usual pointers(ones which we normally use), near pointers and
My understanding is that Google Analytics (the tool I'd normally use for website analytics)
One of the things that seems to be necessary with use of STL is
In grails if you want to map to particular HTTP methods you normally use
I normally use a GET variable i n the URL to determined what data
Anything I do in views that would normally use ajax to open up a

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.