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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:48:16+00:00 2026-06-15T21:48:16+00:00

I am attempting to create my own HashMap to understand how they work. I

  • 0

I am attempting to create my own HashMap to understand how they work. I am using an array of Linked Lists to store the values(strings) in my hashmap.

I am creating the array like this:

Node** list;

Instead of this:

Node* list[nSize];

This is so the array can be any size at runtime. But I think I am getting a memory leak because of how I am doing this. I dont know where the error is but when I run the following simple code the .exe crashes.

Why is my application crashing and how can I fix it?

Note: I am aware that using a vector would be much better than an array but this is just for learning and I want to challenge myself to create the hashmap using a ‘Dynamic’ Array. PS: is that the correct term(Dynamic Array) for the kind of array I am using?

struct Node
{
  // to implement
};

class HashMap
{
  public:
     HashMap(int dynSize)
     {
        *list = new Node[dynSize];
        size  = dynSize;  

        for (int i=0; i<size; i++)
            list[i] = NULL;

        cout << "END\n";
     }

     ~HashMap()
     {
        for (int i=0; i<size; i++)
           delete list[i];
     }

  private:
     Node** list; // I could use a vector here but I am experimenting with a pointer to an array(pointer), also its more elegant
     int    size;
};

int main()
{
   // When I run this application it crashes. Where is my memory leak?
   HashMap h(5);

   system("PAUSE");
   return 0;
}
  • 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-15T21:48:17+00:00Added an answer on June 15, 2026 at 9:48 pm

    You need to follow the Rule of Three.

    Provide a copy constructor and copy assignment operator which make deep copies of the dynamically allocated member.

    Besides,

     Node** list; 
     *list = new Node[dynSize];
    

    Just deferences an uninitialized pointer. *list does not point to anything meaningful since list was never initialized.

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

Sidebar

Related Questions

I am in the process of creating my own linked list. I am attempting
i've been unsuccessfully attempting to create my own undo/redo classes that work well with
I'm attempting to create my own templates for the search pages using drupal 6.
I'm attempting to create my own todo list using Javascript, Python and MongoDB. I'm
I'm attempting to create my own double linked list for learning experience. My book
I am attempting to create my own custom Autocomplete style dropdown control in c#
I'm attempting to create an automated script on my own site which logs into
Im attempting to create a new operator :? on lists, which operates the same
I attempting to create custom tabs using this . But when I try to
I'm attempting to create a table for monitoring purposes using the following script: $w3wppriv

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.