HNHacker News
TopNewBestAskShowJobs

mihai_ionic

266 karma · joined October 12, 2012

submissionscomments
mihai_ionic··on AMD Introduces "Mantle" API Initiative
VOD of the announcement is available here: http://www.livestream.com/amdlivestream/video?clipId=pla_334....

Mantle information starts at 02:26:40.

mihai_ionic··on AMD announces Mantle, a low-level graphics API replacement for Direct3D/OpenGL
More information still coming out on the live stream: http://www.livestream.com/amdlivestream.

Edit: It's over now. The VOD is available here: http://www.livestream.com/amdlivestream/video?clipId=pla_334.... Mantle information starts at 02:26:40.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative

    template <typename T>
    void remove(std::vector<T>& v, std::size_t i)
    {
        std::swap(v[i], v.back());
        v.resize(v.size() - 1);
    }
mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
That's not what he said, and his solution is not "inefficient." CPUs have no emotions; if it runs faster due to cache, it's simply the better solution.

For the use case required by ZeroMQ, it's faster in all cases, because swap-with-last and shrink is O(1). Sure, if CPUs didn't have caches, a list might be faster.

Do you see where this is going? The C way of solving problems consists of adding one more level of indirection (ever heard of 3-star C programmers?), because it becomes more efficient asymptotically that way. Nevermind the hidden factor of 100-1000 due to pipeline stalls and cache misses.

Fortunately not all C programmers think that way.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
Even in C, setjmp/longjmp leave all non-volatile automatic storage duration variables on the current stack frame in an indeterminate state if they are modified between the two calls.

To get defined behaviour with regards to destructors, you simply have to make sure that the function calling setjmp doesn't internally use RAII. Call a wrapper function to do the setjmp and you're safe.

Of course it's a whole other question whether using setjmp/longjmp to implement "exception handling in C" is a good idea in the first place.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
I'd like to know what restrictions cause you not to be able to use RAII.

Even if that's the only C++ feature that a project were to use, I'd still consider it a net gain. Anything that makes your program less susceptible to manual resource management bugs in "goto cleanup"-style C is worth using. This doesn't just include memory leaks, but more insidious problems like unclear ownership of various system resources (sockets, file handles...). Things not even a GC would help you with in a long-running server process.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
Add the modern L4 microkernels to that list, e.g.: https://github.com/l4ka/pistachio
mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
1) It's 2013, all major compilers (GCC, Clang, MSVC, ICC) have supported rvalue-references for multiple releases.

2) You missed the part where there's nothing preventing anyone from using intrusive lists in C++.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
Since you never traverse the list, the order of elements obviously doesn't matter. In that case, you can just swap the element to remove with the last element.

A vector will still give you better cache-locality and also amortize the number of allocations.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
If you can use C++11, this becomes a non-issue with move semantics.

Ownership of internal resources can be transferred, and emplace_back even allows constructing your object in place.

As others said, the O(n) really becomes more like pseudo-O(1) due to cache effects unless you have elements the size of your cache lines (in which case prefetching still helps) or you're only fetching one element at a time and then triggering a context switch (as in a scheduler).

I'm not bashing your library, and if you prefer to use C then that's great, but it's kind of unfair to blame it on the language in the first place.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
The point of intrusive lists is to allow access to the link when you provide only the contained object.

The way you're thinking of would theoretically work, but you'd have to make sure the compiler isn't adding fancy padding that would break your pointer manipulation and type casting.

boost::intrusive::list on the other hand, works in a type-safe manner by having your class either inherit a list hook, or provide it as member and then pass the list implementation a member pointer as template parameter so that it can be accessed.

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
No, the ZeroMQ author should be writing idiomatic code in whatever language he is using.

In his blog post, he complains that std::list<widget* > causes 2 allocations per insertion. Fine, because that's not idiomatic C++. The C++ way would be to use std::list<widget>, since there's no need for the extra indirection. Note that this would only be a good choice if you for some reason really need a list, std::vector is mostly preferred due to its better cache behaviour and requires even fewer allocations.

Secondly, if he needs to remove list items by their address, there's no reason he couldn't use an intrusive list in C++. The article I linked shows an implementation of one, and there's always boost::intrusive::list if you don't want to roll your own (and you shouldn't).

mihai_ionic··on Nanomsg – MIT-licensed ZeroMQ alternative
It has also been pointed out that these problems are not intrinsic to C++, but rather due to the way he was using it: http://www.codeofhonor.com/blog/avoiding-game-crashes-relate...
mihai_ionic··on Linus Torvalds - C++ is a horrible language
Seeing as I consider Qt to be a particularly badly designed C++ library, this speaks volumes about how cumbersome some C APIs are to use. Not that there is any real alternative for a cross-platform UI toolkit.
mihai_ionic··on Linus Torvalds - C++ is a horrible language
> That said, avoiding libraries (especially avoiding templates and just using void*-like stuff) does keep binaries/libs smaller, but I'll gladly make the computer work slightly harder considering that the result is the same speed (C++ is often faster than C, in practice).

This should not be an issue with modern C++ compilers. If two template instantiations generate the same or similar code, they will be merged and useless code is removed by dead code elimination.

> The downside I care about is compilation speed. Simple C projects compile/link faster than modern C++ ones, even though the code for the same functionality is far more brittle, unsafe, and opaque

At the same time, a lot of potential for optimization is lost by barricading everything between translation units and/or behind opaque pointers. While yes, LTO is supposed to help there, all those memory accesses make it infinitely harder for the compiler to prove trivial properties about the data flow. See also this recent presentation by someone who has a lot more experience than me with writing compiler backends: http://www.youtube.com/watch?v=eR34r7HOU14

mihai_ionic··on Partially Applied Functions in C
I knew I should have just called it bind.

As a bonus, an actual implementation of curry: https://dpaste.de/qGWcq/

mihai_ionic··on Partially Applied Functions in C
C++14 version: https://dpaste.de/a8g9D/

You obviously can't pass this to C code, but it's a portable and extremely efficient solution if you are working purely within a C++ code-base.

mihai_ionic··on Google: search for an application
Nice, my application which is not even on page one in Google Play search appears as the first result for the same keyword in Google Applications.
mihai_ionic··on Reading someone's Gmail doesn't violate federal statute, court finds
Isn't it a backup of the data in the person's brain, and thereby considered "electronic storage"?
← PreviousPage 2 of 2