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: 318 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 10 h 22 m 21 sec
Reputation Power: 3
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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT