D. Jurcau
  • Member for 6 years
  • Last seen more than a month ago
Find a bitmap within another bitmap
Accepted answer
16 votes

Accessing the Pixels GetPixel() is notoriously slow for iterating through the whole bitmap. Consider using LockBits for accessing the pixels directly in memory. After making sure the alpha channel is ...

View answer
Implementing realloc in C
13 votes

You are checking if malloc succeeded before calling memcpy, but not before calling memset. You are copying len bytes from ptr to the new memory location, but don't know how many bytes ptr actually ...

View answer
C Socket Part-1
11 votes

One of the issues with TCP sockets is that there's no guarantee that sending N bytes in one go will result in receiving exactly N bytes after one call to read(). I would thus emphasize this by using a ...

View answer
Merging two files containing sorted numbers into one
10 votes

As the others have pointed out, there is a lot of repetition in your code. This is however a great opportunity to threat the files as simple iterators from which you can extract integers. This is ...

View answer
Solving Fizz Buzz using LINQ in C#
9 votes

The comments mention being reusable as the main goal of the code. It is however far from it. The main issues I see with most of the extension methods above: Looking at the name of the methods (and ...

View answer
Searching an element in an alternately sorted array
7 votes

How about an alternate approach: instead of adapting the binary-search algorithm to work with all kinds of alternate sorted collections, how about adapting the collections to be able to run classic ...

View answer
60GB file loading domain to base domain + tld parser
6 votes

A 60 GB file fits a lot of domains. Reporting progress after each of them results in so many calls, that the application may end up spending more time reporting the progress than doing useful work. ...

View answer
C++ simple enumerator implementation
Accepted answer
6 votes

enumerator::emplace_back() Methods like push_back or emplace_back don't belong in an enumerator. Like the name says, the enumerator's job is to enumerate a collection, not to provide all the features ...

View answer
HTTP downloader using Beast
Accepted answer
6 votes

Missing Headers Before going any further, the current code is missing a few headers that it needs, namely: <functional> and <memory>. Navigating to Location doesn't work Next, I've ran ...

View answer
Async TCP client/server
Accepted answer
6 votes

Async/Await Async/await's main advantage is that you no longer need to use ContinueWith() to chain tasks, making the code much cleaner. Your code seems to more often favor the use of ContinueWith(). ...

View answer
Bubble Sort Implementation | C-ish and Modern C++
Accepted answer
5 votes

As you're already working with iterators you might as well accept iterators as arguments instead of the std::vector (as all STL algorithms do). That way it will work with other containers as well, ...

View answer
Handling Server Responses
5 votes

Having bool Succeeded, bool Failed and bool Errored as members of the GatewayResponseHandlerResult class is a very bad practice. Not to mention that all of them are public mutable so that any code can ...

View answer
Reading strings into a vector, without using namespace std
5 votes

Using a range-based for loop makes the loop much easier to read #include <iostream> #include <vector> int main() { std::string text; std::vector<std::string> vector; ...

View answer
Brute-force search for solution to an unsolved mathematical inequality
Accepted answer
5 votes

A first step in optimizing would be to avoid computing the same values multiple times. Secondly, I would drop the floating point arithmetic altogether. You have integer bases with integer exponents, ...

View answer
Sending email using libcurl
5 votes

C VS C++ Your question is taged with both C++ and C++14, yet the only C++ part in your code seems to the use of std::string. Use RAII As you are using a C library, creating a small wrapper around ...

View answer
Trie implementation in C++
4 votes

Memory Management You're using new to allocate memory in quite a few places, but I don't see any matching delete call to also free it. Don't pass complex objects by value You're accepting std::...

View answer
C# to C++ function call that fills and auto resize array if size is not enough
4 votes

I believe a much simpler solution would be to simply ask the unmanaged code how much memory it requires, without doing any other operation in the unmananged code if the buffer passed it is not large ...

View answer
CSV parsers and OrderedDictionary
Accepted answer
4 votes

Naming Items You should avoid abbreviations like Dict in DictReaderCSV, spelling it Dictionary is cleaner. Next, it's much more natural to use nouns for class names and verbs for methods. As such, I ...

View answer
TCP authentication server and client
Accepted answer
4 votes

You seem to be doing a lot of low-level byte manipulation when using the sockets. Once you have a NetworkStream, just wrap it inside a StreamReader/StreamWriter and let them handle sending strings ...

View answer
C++ Node class template
Accepted answer
4 votes

In the case of linked lists, the pointer to the next value should be a pointer to another Node instance, not a pointer to another data entry. This would allow you to walk the entire list node-by-node. ...

View answer
HTTP Response/Request Class
4 votes

I don't quite see the purpose of your class. You are basically taking an existing class from the .NET Framework and wrapping it up in something that only exposes a fraction of the functionality. The ...

View answer
Find numbers between 1 and 10000 whose sum of digits are prime
4 votes

The sum of the digits is such a small number (9+9+9+9=36 the maximum in your case) that you can even hard-code the values which are prime or not: //number: 1 2 3 4 5 6 7 char isPrime[] =...

View answer
a simple implementation of unix2dos for windows
3 votes

It takes some time to navigate through all the error logging to reach the code that actually does the line ending conversion. Avoiding standard library functions doesn't mean you can't write some ...

View answer
52-Line Logging System
Accepted answer
3 votes

Macros Most of your code is in a macro. This makes it harder to write, read and debug. Why not place the logic in normal functions and only use macros to pass __FILE__ and __LINE__? That is until you ...

View answer
I'm deallocating objects created but I'm unsure whether my code is leaking memory or not
3 votes

You don't need to use new everywhere. Inside your main function, the StudentDatabase could very well reside on the stack so you don't need to delete it yourself. One of the issues with how ...

View answer
Rotate square matrix clockwise by 90degrees
3 votes

As memory management is one of the question's tags, writing swap that way is NOT the way to go: Harder to understand Risks overflows Is less efficient when looking at the compilation result: https://...

View answer
MySQL/MariaDB Data extraction / String manipulation / "TopN" processing => Performance of C++ vs php vs python
3 votes

String Operations You're copying a string and then starting to make various transformations to it. As std::isspace and std::tolower end up being called and can have quite complex logic, avoiding them ...

View answer
First stage of a complex calculator implementation in C++
Accepted answer
3 votes

Never write using namespace ... in a header. You're forcing users of your library to do something they almost certainly don't want to do. Don't pass strings by value. Pass them by const reference (to ...

View answer
Printing an N*N array in the rectangular/circular/spiral fashion
3 votes

Inappropriate names The names you used make your code almost unreadable: what is a class called arr or first supposed to represent? What should a function called t do? Wrong use of OOP Your arr ...

View answer
C++ Socket syncronous poll wrapper
Accepted answer
3 votes

Your socket abstraction doesn't offer many features. For example, I don't see any way of closing a TCP connection. get_peer_name() could be made available on any type of socket and you could also ...

View answer