Industrial Strength Hash Table

Started by
15 comments, last by swiftcoder 10 years, 1 month ago


Using braces instead of brackets for trying to call the constructor of an object

That's actually valid in C++11 and called uniform initialization syntax.

Advertisement


Using braces instead of brackets for trying to call the constructor of an object

That's actually valid in C++11 and called uniform initialization syntax.

Thanks for the clarification. I learned something new today!

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty

i'm starting to have a trauma


EDIT: Or the fact that every function is terminated with a semicolon. Again, personal preference; hell of an annoying one.

WTF I didn't notice that at first.

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty
Using delete[] on objects created with new and not new[]

Relax, it is much worse than you think.laugh.png

delete[] is being called on objects which are not explicitly allocated via new at all. The vectors that are allocated on the heap are copied (if the compiler accepts this code at all!) and then leaked. I wonder how you can assign a pointer-to-vector to a vector though, since to my knowledge it only accepts const T& and T&& and std::initializer_list<T>.

Both keys and values are objects, not pointers, and part of the Dictionary object. Which means that you call delete (with or without brackets, who cares) on an object that is either allocated on the stack or inside a larger heap-allocated object. In either case, this is very bad mojo.

The Dictionary class has no virtual functions and keys is the first member, so likely (void*) keys == (void*) dictionary_object

Which means if you somehow get the compiler to accept this code (I would be surprised, though), it would double-delete the Dictionary object, once explicitly and once from its own destructor via a type-punned std::vector pointer.


EDIT: Or the fact that every function is terminated with a semicolon. Again, personal preference; hell of an annoying one.

Haha, but get this, only some functions are terminated with a semicolon. Others aren't.

This looks like Java code that someone tried to port without an actual understanding of C++.

This looks like Java code that someone tried to port without an actual understanding of C++.

That reminds me of a joke which has become decidedly unfunny on my current project:

What's worse than C++ written by a Java developer?

[spoiler]Java written by a C++ developer.[/spoiler]

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement