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

  • Home
  • SEARCH
  • 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 7972085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:46:35+00:00 2026-06-04T07:46:35+00:00

I’ve started a project in C++. Memory management in this language is new to

  • 0

I’ve started a project in C++. Memory management in this language is new to me.

I used to create objects with new () and then pass around pointers and while it worked, it was a pain to debug and people looked at me funny when they saw the code. I am quite proud of the fact that it didn’t leak or segfault (once fixed), but it really was a lot of effort.

list <struct Connection *> users;

struct Connection * accept_connection (const char *name) {
  struct Connection * new_node = new Connection ();
  new_node->_data = ... // whatever, set it up here
  return new_node;
}

struct Connection * new_user = accept_connection (const char *name);
users.append (new_user);

So I have a new strategy for this next version of the project. So far what I am doing is creating objects with new () and assigning them a unique integer ID number. I then store the object in a hashed table using the ID as a key. Now items are stored and passed around by the integer ID number and when you do need to de-reference it, you go to the hash table and it returns you either thing * or NULL. Hence I no longer experience pointer errors but the speed of the code is somewhat reduced.

typedef unsigned long ID_Number;

// create a user and return the ID
ID_Number create_user () {
  ID_Number new_id = assign_unique_id ();
  struct User * node = new User ();
  node->_id = new_id;
  node->_data = ... // whatever, set it up here
  add_to_users_dict (new_id, node);
  return new_id;
}

list <ID_Number> users;

for_each (users.begin(), users.end(), process_user);

void process_user (ID_Number i) {
  struct User * u_ptr = lookup_user_dict (i);
  if (u_ptr == NULL) {
    // not found in dict
    // somehow this guy was deleted
  } else {
    // we can do stuff with this guy
  }
}

Now I am sort of familiar with the basic tenets of programming but being a self-taught hobbyist I am not familiar with the industry practices and tools.
What I am basically asking for, is guidelines on memory management:

1) What am I doing right or wrong?

2) Are there any packages or libraries I can use that would help me?

3) What the the standard practices of the industry?

4) Basically what should I be googling or buying for kindle etc?

Today I usually use Python, it does handle a lot of “back end” stuff for me, but I need C or C++ (I guess I’m using plain C plus the stdc++ libs, I am not quite sure where the overlap between the languages is – I just know g++ compiles it fine) for this one particular project for speed/performance reasons: although I suspect some maths genius could provide algorithmic fixes that would speed it no end, though that’s a separate question.

  • 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-04T07:46:36+00:00Added an answer on June 4, 2026 at 7:46 am

    The best answer I can give, is you shouldn’t use pointers in the traditional way. C++11 has changed the way the programmer deals with memory management.

    Rather than explaining things that have already been explained in detail by people far more intelligent than myself I will just provide some links.

    The first you should look at is Herb Sutter’s Article Elements of Modern C++ Style
    Then check out the video by Bjarne Stroustrup C++11 Style

    If you are able to use the new C++11 standard you should, it makes memory management much cleaner than before.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.