|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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). Last edited by davidthefat : 22-02-2011 at 18:51. |
|
#2
|
|||
|
|||
|
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[]
|
|
#3
|
|||
|
|||
|
Re: Programming Help!
Quote:
That is what programming in Java 24/7 does to your mind. I almost forgot about that.![]() |
|
#4
|
||||
|
||||
|
Re: Programming Help!
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:
This is a situation where it would be useful to post the console output. The debugger would also be a valuable tool to use. Last edited by MattD : 24-02-2011 at 08:01. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
Re: Programming Help!
Quote:
That's right, and I was not even thinking about that. Good catch. My previous post was incorrect.Last edited by MattD : 24-02-2011 at 07:56. Reason: quoted previous post |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|