Go to Post Ban the ingredients for cheesecake, and stores will find substitutes. Remove the market for them, and stores have no reason to make them. - Rachel Lim [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2011, 18:42
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Programming Help!

Memory leak? You have to be really careful when using malloc. That is if you don't know what you are doing, just use "new". You never freed your allocated data.

Add:
free(Elevator_heights);
after that for loop

edit: my analogy I like to use is like feeding a kid a whole bunch of food and not letting him poop afterwards. So that stays inside of him until you let him poop or he dies (the program exits).
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.

Last edited by davidthefat : 22-02-2011 at 18:51.
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2011, 11:06
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Programming Help!

you have to be just as careful whether your using new or malloc. maybe even a little more careful when using new because then you have to choose correctly between delete and delete[]
Reply With Quote
  #3   Spotlight this post!  
Unread 23-02-2011, 18:35
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Programming Help!

Quote:
Originally Posted by jwakeman View Post
you have to be just as careful whether your using new or malloc. maybe even a little more careful when using new because then you have to choose correctly between delete and delete[]
That is what programming in Java 24/7 does to your mind. I almost forgot about that.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #4   Spotlight this post!  
Unread 23-02-2011, 22:17
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Programming Help!

Quote:
Originally Posted by davidthefat View Post
Add:
free(Elevator_heights);
after that for loop
I'm not sure why this would be freed at after that for loop. It looks like there are other functions that want to access that array later on. It should be freed somewhere else (perhaps a destructor), but I don't think that this is the source of the problem. It appears it's only called at most twice during the program's run before it crashes.

As mentioned already, that Elevator_Mechanism structure is very strange looking. It's difficult to follow, so I can't say for sure whether or not that part would work.

Spoiler for incorrect information:

Here's what I noticed at a quick glance in the constructor's initialization list:
Code:
Carriage_motor(new Victor(4)),
Elevator_motor(new Victor(3)),
These are defined earlier as:
Code:
Victor *Elevator_motor;
Victor *Carriage_motor;
I believe you should have instead:
Code:
Carriage_motor(3),
Elevator_motor(4),
This is because the constructor for Victor expects an int with the value of a PWM port, and instead you're passing a pointer to a Victor. Since there are checks to make sure a valid PWM channel number is provided, I'd expect an IndexOutOfRange ("Allocating channel or module that is out of range") fatal error to be thrown by WPILib.

This is a situation where it would be useful to post the console output. The debugger would also be a valuable tool to use.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award

Last edited by MattD : 24-02-2011 at 08:01.
Reply With Quote
  #5   Spotlight this post!  
Unread 24-02-2011, 00:41
CodeMonkeyMatt CodeMonkeyMatt is offline
Registered User
FRC #2605
 
Join Date: Jan 2011
Rookie Year: 2008
Location: WA
Posts: 46
CodeMonkeyMatt is on a distinguished road
Re: Programming Help!

Good catch on the constructors. Actually though, I think the whole lines for the Carriage motor and elevator motor before the "{" braces should be taken out. Since those are declared as pointers, you use the "name = new ClassName(args);" format in the actual constructor, which you were doing, but then commented out.

If you declared the objects as actual objects instead of as pointers (i.e. Victor Elevator_motor; Victor Arm_motor; instead of Victor *Elevator_motor; Victor *Arm_motor; ) then you would use the format described by MattD.

As always, I'm only a fallible student, so someone feel free to disprove me.

Last edited by CodeMonkeyMatt : 24-02-2011 at 00:42. Reason: Syntax turned into smile
Reply With Quote
  #6   Spotlight this post!  
Unread 24-02-2011, 07:55
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Programming Help!

Quote:
Originally Posted by CodeMonkeyMatt View Post
Since those are declared as pointers, you use the "name = new ClassName(args);" format in the actual constructor, which you were doing, but then commented out.

If you declared the objects as actual objects instead of as pointers (i.e. Victor Elevator_motor; Victor Arm_motor; instead of Victor *Elevator_motor; Victor *Arm_motor; ) then you would use the format described by MattD.
That's right, and I was not even thinking about that. Good catch. My previous post was incorrect.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award

Last edited by MattD : 24-02-2011 at 07:56. Reason: quoted previous post
Reply With Quote
Reply


Thread Tools
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
Forum Jump


All times are GMT -5. The time now is 17:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi