C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 1st, 2007, 09:43 AM
PistoL PistoL is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 16 PistoL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 52 sec
Reputation Power: 0
General - Help Memory Error- Linked List C++

Hi, I am getting a memory error and I cannot figure out why, the message itself does not give much information, so I will list my code, for those interested the message reads

"Unhandled exception at 0x00411b09 in MapClass.exe: 0xC0000005: Access violation reading location 0xcdcdd071."

Anyways, I have got a Hash Table class, and a Linked List class, the Linked list class is not mine, I am using a provided one from the following source http://sig9.com/node/312 (The single one)

I have created an array of these linked lists in my hash table class

Code:
LinkedList *Table = new LinkedList[Size];


the function I have a problem with is the following:

Code:
bool CHashTable::Add(char* data)
{
	int KeyValue = Hash(data);

	Table[KeyValue].insert(data);
	
	count++;
	return true;
}


The Hash function just returns a value (93) to be precise and then we use this as to access that specific array element in Table, however when i call the insert function from the LinkedList (see http://sig9.com/node/312), when it runs the SetData(See http://sig9.com/node/312) function I get a memory leak?

Ive tested the LinkedList class and there is no problems with it, I dont see why as I have passed a char pointer to it like it asks, it works if I just use the Linked List on its own and send in a char pointer, it inserts it fine.

Please let me know if you need to see more code, thanks

Reply With Quote
  #2  
Old December 3rd, 2007, 01:23 AM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 329 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 13 h 57 m 18 sec
Reputation Power: 4
Send a message via AIM to Bobidybob
how big is the Table? is 93 past the end of it?

what is the smallest possible value to be returned from Hash()? 1 or 0? if its 1, you may have to do Table[KeyValue - 1] to prevent going over the end of the array.

is it throwing the error at compile time or run time? compile time doesnt make sense as the code for Add() seems fine, and if its at run time, you'll need to post the code of the data you're actually passing to Add() and what you expect to be more helpful.

iono, hope this is helpful, i just kinda glazed over the problem... time for sleep...
__________________

Reply With Quote
  #3  
Old December 3rd, 2007, 01:21 PM
PistoL PistoL is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 16 PistoL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 52 sec
Reputation Power: 0
The error is at runtime, it compiles fine.

Everything seems in range, the add function is called using:
Code:
HashTable->Add("Lolipops");


so i send in "Lolipops" as a char pointer.

The Hash() returns the value 42 which is easily in the range as the max array size for Table is 101.
Code:
Table[KeyValue].insert(data);


The line above gives the problem, as it runs the insert function in the linked list it throws an error in the SetData function, you can look at this linked list in the link I specified above, the data passed into it is a char pointer called data and contains "Lolipops"

Below is some of the code from the LinkedList that is causing giving me the error, ps I have tested the linked list and it seems correct and works when i use it on its own

Code:
void LinkedList::insert(char* x) {
  m_curr->setData(x);
  m_curr->setNext(new LinkedList(m_start)); 
  m_curr = m_curr->getNext();
}

void LinkedList::setData(char* el) {
  m_data = el;
}

Reply With Quote
  #4  
Old December 3rd, 2007, 01:56 PM
PistoL PistoL is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 16 PistoL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 52 sec
Reputation Power: 0
Thanks for the post bobidy bob but I have just fixed it, it was a stupid copy error grrr.

in my private members I had:

Code:
LinkedList *Table;


then is my constructor I had
Code:
LinkedList *Table = new LinkedList[Size];


which is stupid as its supposed to be

Code:
Table = new LinkedList[Size];


not creating a brand new linkedlist pointer lol

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - Help Memory Error- Linked List C++


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.


© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek