« first day (643 days earlier)      last day (2216 days later) » 

1:53 AM
Hi! I just wrote a huffman encoding algorithm, or tried to using C++ classes and such. I think it should work, but it keeps crashing at new node creation for some reason.
Node* Heap::newNode(char _data, int _freq)
is function it crashes in on the line:
Node* temp = (Node*)malloc(sizeof(Node));
I've tried using Node* temp = new Node;
But that doesn't work either.
pastebin.com/6Jf0YVN4 Could someone please take a look?
Not sure where it's going wrong
 
 
2 hours later…
4:06 AM
@Annabelle use valgrind
in Lounge<C++>, Mar 22 '16 at 20:12, by milleniumbug
@sehe I run process in valgrind with valgrind --vgdb=yes --vgdb-error=0 ./my_program and then I follow the instructions (as in, running gdb ./my_program and paste in target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=PID)
context: crashing on memory allocation means you have corrupted memory, possibly by either writing out of bounds, or by freeing twice
also, I'm going to assume this is a uni exercise
because otherwise you wouldn't reimplement heaps since they are provided by your standard library (std::make_heap, std::push_heap, std::pop_heap)
 
 
10 hours later…
2:18 PM
Don't think valgrind works on windows, does it?
 
no
 
2:30 PM
All things being equal, should I prefer using references over smart pointers given a choice between the two?
 
@nobism different use cases
it's like asking if you should use a screw to prop up a shelf
 
 
1 hour later…
3:43 PM
@Mgetz LOL
 
 
2 hours later…
5:42 PM
Ugh can't find error
 
6:18 PM
lets say i have a class named Obj with a constructor. when i do for example Obj x = new Obj(); is the keyword new calling the constructor Obj() ?
what is the keyword new doing?
 
6:48 PM
Allocating memory for the object. @jeyejow
 
ohhhh
so that why they say to use delete if we use new
 
Yeah
 
7:45 PM
hey guys
does anyone else find reading the graph theory bit in clsr hard?
 
which part in particular
 
chapter 22
its so dry
and i cant visualise it enough
 
I'd say skip the proofs and lemmas, check out the images first, then go back to the description
 
yeah im not too interested in the proofs
my maths is strong enough to understand anything that i would need to if i had to
do you use this stuff in your work?
/anyone
 
can't tell, I don't have a job
 
7:54 PM
ever had a job?
sometimes some of this stuff im not sure is worth learning
because some of algorithms could be created by a smart guy for a particular need that arose
 
there is a chapter (fibonacci heap) in CLRS I skipped because it had itself said "this data structure is not practical in real life, but the theory behind it is interesting" at the very beginning of the chapter
 
i read some guy from facebook on quora who said to skip that chapter
 
oh, the book says that while asymptotic time complexity of operations for fibonacci heap is lower than alternatives, the real world performance bonus is only possible with a very large number of elements
 
8:16 PM
lol
im going to watch on this instead
 
9:07 PM
What does not returning anything from a function that should return something (according to its declaration) not provoke a compiler error? I suspect that the function might be too complicated to catch this ... halting problem. But it could at least check for the keyword.
 
Pretty sure if you -Wall -Werror it wont compile
 
sure
My question is: Is it not checked because of the halting problem?
 
@Nils It is not checked because it's also not checked in C. Suddenly adding the requirement breaks previous code. C hasn't checked it because it's ~~effort~~.
 
halting problem doesn't come into it, other languages will check it
 
6 messages moved from Lounge<C++>
Another reason is that historically, void type didn't exist in C
and a function with no meaningful return value would be written like any other function
f(x) char* x; { int i; for(i = 0; i < 20; ++i) { x[i] = '\0'; } }
^ the return type is not specified, so it's int. We can't say void because it doesn't exist yet. But we also don't have return because we don't have anything to return.
 
9:56 PM
i'm learning about variadic templates and template templates, widening my scope of knowledge...
 
10:06 PM
Template templates? What are those for?
 
@JackOfBlades templates structured inside templates :) or nested templates in other terms.
 
10:31 PM
@Permian never! or just not yet.
 
 
1 hour later…
11:31 PM
All things being equal, should I prefer using references over smart pointers given a choice between the two?
 
9 hours ago, by Mgetz
it's like asking if you should use a screw to prop up a shelf
 
@Mgetz That's why I said 'all things being equal'. Lets say a class has a variable which is an interface, should it be a reference or a pointer?
 
you should pass things by reference rather than by smart pointer
 
@Mikhail Ok, thanks.
 
Mar 10 at 0:50, by sehe
@Mikhail Really. I rarely see questions about smart pointers.
 
11:40 PM
@Mikhail badam-tish!
 

« first day (643 days earlier)      last day (2216 days later) »