IT/Software career thread: Invert binary trees for dollars.

  • Guest, it's time once again for the massively important and exciting FoH Asshat Tournament!



    Go here and give us your nominations!
    Who's been the biggest Asshat in the last year? Give us your worst ones!

Tenks

Bronze Knight of the Realm
14,163
607
Could it be that your methods return Book() when nothing is found when more realistically they should be returning NULL? I don't really feel like running through all the source to determine the memory leak. Just carefully check out everytime you allocate memory and determine if it is necessary and if you manage it.

Actually looking through the merge code it appears the code expects all returns from the get to be non-null. So you may not be able to do that. Not entirely sure what the purpose of the first loop is in the merge code, though. Since add is guaranteed to have non-dupes I don't know why the code doesn't just instantiate a new catalog and add all items from cat1 and cat2 and return the result. *Shrug*
 
Last edited:

Tenks

Bronze Knight of the Realm
14,163
607
And... no idea why delete [] books doesn't work. Crashes on runtime.

Whats the error? I'm not a C++ programmer so this is a bit out of my depth but I think the problem may be since you're doing newBooks[x] = books[x] it isn't cloning the Book object so you're putting a reference to the memory location in newBooks[x]. Therefore when you try and free the memory of books[x] it causes the runtime to barf since it loses all references in the new array.

SO discusses it here. I *assume* your teacher wouldn't love you using a Vector (despite it being a much more logical backing for the Catalog) so maybe look into the memcpy.

How to resize array in C++?
 

Eidal

Molten Core Raider
2,001
213
Whats the error? I'm not a C++ programmer so this is a bit out of my depth but I think the problem may be since you're doing newBooks[x] = books[x] it isn't cloning the Book object so you're putting a reference to the memory location in newBooks[x]. Therefore when you try and free the memory of books[x] it causes the runtime to barf since it loses all references in the new array.

SO discusses it here. I *assume* your teacher wouldn't love you using a Vector (despite it being a much more logical backing for the Catalog) so maybe look into the memcpy.

How to resize array in C++?

Says "this application has requested the Runtime to terminate it in an unusual way."

And no, I can't use a vector... has to keep the dynamic array. My question to y'all would be: how do I go about making sure the first two catalogs are deleted once the merged catalog is created? Can I trust the default destructor to clean this up, even though catalogs contain a dynamic array of books?
 

Mist

REEEEeyore
<Gold Donor>
31,539
24,155
I'm not a C++ programmer so this is a bit out of my depth but I think the problem may be since you're doing newBooks[x] = books[x] it isn't cloning the Book object
You're absolutely correct. That's an assignment operation, not a copy.
 

Tenks

Bronze Knight of the Realm
14,163
607
Says "this application has requested the Runtime to terminate it in an unusual way."

And no, I can't use a vector... has to keep the dynamic array. My question to y'all would be: how do I go about making sure the first two catalogs are deleted once the merged catalog is created? Can I trust the default destructor to clean this up, even though catalogs contain a dynamic array of books?

Have you tried just fleshing out the destructor to free the memory of the array? I got to tell you a ton of programming is just trying shit to see if it works.
 

Eidal

Molten Core Raider
2,001
213
Maybe this is a problem in your reserve

  1. delete [] books;
  2. books = newBooks;

Hmm, I swapped the order -- still leaking 606 objects. So my catalog initializes with a capacity of 100 books. A book has 3 strings... 100 books x 3 strings x 2 read-in catalogs. That's 600.

Also, with these small input files I'm not even calling the reserve function...

T Tenks -- I"ve tried a few different variations of the destructor but they all crash... leads me to believe I'm having pointer issues.
 

Noodleface

A Mod Real Quick
38,382
16,303
Well I guess my concern there is you're freeing the memory book is occupying then assigning stuff to it. If it's not called I guess don't worry.
 

Eidal

Molten Core Raider
2,001
213
All my googling is leading me to believe I really need
{
delete [] books;
}

in my destructor... but that single line blows everything up -- program won't run at all.
 

alavaz

Trakanon Raider
2,003
714
Dunno much about cpp.. but this syntax looks odd: books = new Book[theCapacity];

If you want to make an array of book objects, I think you want to do something like: Book* books = new Book[theCapacity]; or even Book books[theCapacity].
 
Last edited:

Noodleface

A Mod Real Quick
38,382
16,303
As far as I take it capacity is dynamic and c++ requires arrays to be use dynamic allocation in such cases.

Eidal Eidal another curious line in the add code:
newBook b;

What does that do?

You're right that your delete is probably the culprit but I'd guess that the initial allocation probably isn't working as required. I can't be at my PC til tomorrow and this is tough to read on my phone.
 

Eidal

Molten Core Raider
2,001
213
As far as I take it capacity is dynamic and c++ requires arrays to be use dynamic allocation in such cases.

Eidal Eidal another curious line in the add code:
newBook b;

What does that do?

You're right that your delete is probably the culprit but I'd guess that the initial allocation probably isn't working as required. I can't be at my PC til tomorrow and this is tough to read on my phone.

Probably just a relic of me fucking around. I'm done messing with it for the night... updated the pastebin with where I left of. Still having the same memory issue -- it's gotta be that it isn't cleaning up the two catalogs it creates to read from the two files.
 

alavaz

Trakanon Raider
2,003
714
Found the book object array declaration in the header, so ignore my previous post. I'd look at your catalog reserve function. It has a 'delete [] books' statement in it that may be messing with things.
 

Lendarios

Trump's Staff
<Gold Donor>
19,360
-17,424
ShakyJake, I have plans to dig into React and Angular. If I remember right React is a facebook creation? Currently, I am looking into jTable as a possible replacement for Datatables. Also looking into Select2.

The push to get off farm solutions has many fighting a losing battle at work, while I have been digging into the client side realm with groups watching how things go. They leave me alone to do my thing and watch, each step I go I see that door close on them. My code is a mess, I know I'm going to get pinged on that once I have to play catchup to help them switch over from CF. I generally dont want to see anyone loss their job, trying what I can to get some of them up on the new stuff coming.

No true developer really wants my stuff, I seem to mess things together to get my results. I got puzzled looks last week with I told them I was getting info crosssite/domain without authentication. You thought I was showing off a free energy device! Showed my messing crap and test examples as proof, it was crickets after that.
*shrug....
React is the way to go
 

Dr Neir

Trakanon Raider
832
1,505
Cool, I have plans to dig into that. Currently having to please a pushy customer. Waiting to get to a point when I can sit down and redo the code...again. I soo hate SOAP....
Average BS, they see part of it and then want it pushed out. Sure the body of the car is done and has 3 wheel, it might work if you push it down hill. Nvm the fact its missing a motor and cant turn. ROFL!
 

Tearofsoul

Ancient MMO noob
1,791
1,257
Finance degree here, But end up working in IT as network engineer, CCIE to be specific. High demand job, good money, flexible schedule, not much stress. (If you don't like coding but want to do computer related stuff, consider this)
 

Ao-

¯\_(ツ)_/¯
<WoW Guild Officer>
7,879
507
Finance degree here, But end up working in IT as network engineer, CCIE to be specific. High demand job, good money, flexible schedule, not much stress. (If you don't like coding but want to do computer related stuff, consider this)
Getting the CCIE is no joke though :p