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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:20:34+00:00 2026-06-09T12:20:34+00:00

I am porting some Java to C++ and rather naively jumped in to using

  • 0

I am porting some Java to C++ and rather naively jumped in to using std::vector.

Here is my problem. I have a repository of objects and at some point later I will require
a list of objects from this repository that satisfy some condition. Currently I am reading them into a temporary std::vector. It turns out that when this temporary goes out of scope
it’ll delete its contents and of course that’ll lead to dangling pointers in the repository.

This is my current ‘workaround’, that I find particularly disgusting.

#define NULLIFY(aParam) \
{ \
    for (size_t i = 0; i < aParam.size(); i++) { \
        aParam[i] = NULL; \
    } \
}

typedef std::vector<Object*> TObjectVector;

int main(int argc, char* argv[])
{
    PopulateRepository(); // repository uses std::set

    TObjectVector subset;
    Repository.GetConditionSatisfyingObjects(subset);
    DoSomething(subset);

    NULLIFY(subset); // Stop destruction of the objects.
}

I’m open to other ideas. I did originally have it all working with raw pointers and dynamic allocation but I wanted to see if there was a speed-up with using STL as I’d have less parameters to pass around. The program is multithreaded and quite CPU intensive.

  • 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-09T12:20:35+00:00Added an answer on June 9, 2026 at 12:20 pm

    If you have a vector of pointers such as std::vector<Object*>, the Object destructors will not be called.

    And if you have a vector of objects, such as std::vector<Object>, then you store copies of whatever gets “put” in the vector. So I am not sure where the dangling pointers could come from.

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

Sidebar

Related Questions

I am porting some of our app from c# to java. Some data objects
I have some C++ code I am porting to Java. My code looks something
I'm just porting some code over from .net to Java. I've been using the
I'm currently porting some work from MySQL to Google App Engine/Java. I'm using JDO,
I have some code that is Java EE 5. I want to start porting
I'm porting some C++ to Java, and encountered the following shorthand..but have no idea
I'm in the process of porting some Java processing code to ruby-processing , and
I am porting some C# code over to Java. I am having trouble with
I'm looking at porting some code that uses java.util.concurrent.ConcurrentSkipListSet to an environment where this
We're porting a legacy Java app to JRuby and would like to reuse some

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.