Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    H

    HTTrack Blog

    blog.httrack.com · Company blog · on HN since 2013

    The HTTrack Blog is written by the developer of HTTrack and covers low-level C and C++ topics like fsync, realloc, compiler flags and Android signals.

    Visit blogHN submissions
    Systems & PerformanceProgramming
    What HN says

    Commenters cite it as a useful reference on fsync's unreliability and file durability, realloc remapping memory for large allocations, and Android signal handling.

    Stats for nerds
    15HN people shared it
    9linked in comments
    402story points
    Oct 2020last shared
    2014people per year2020

    Top posts on HN

    1. 1
      What Are Your GCC Flags?
      1 person · 174 points · first shared 2014 · 114 comments on HN
    2. 2
      A Story Of realloc (And Laziness)
      4 people · 130 points · first shared 2014 · 63 comments on HN
    3. 3
      Redirecting Stdio is Hard
      2 people · 57 points · first shared 2014 · 15 comments on HN
    4. 4
      Things to Know About Fsync (2013)
      5 people · 35 points · first shared 2015 · Discussion on HN
    5. 5
      Standalone Visual C++ Compiler
      1 person · 3 points · first shared 2014 · Discussion on HN
    6. 6
      Compiler-error-abuse-based large scale renaming in C++
      1 person · 2 points · first shared 2022 · Discussion on HN
    7. 7
      An Unusual Case of Case (/switch)
      1 person · 1 points · first shared 2013 · Discussion on HN
    8. 8
      I found a bug in strncat
      1 person · first shared 2015
    9. 9
      I do not want your search bar
      1 person · first shared 2015
    10. 10
      Catching posix signals on android
      1 person · first shared 2016

    What HN people wrote when they linked it

    • userbinatorNov 2014

      This argument in this article is mainly based on a naive realloc() that does allocate-copy-free, but on a system with virtual memory the memory allocator should be able to reallocate by modifying page table entries, which is far faster than copying the data around; in the (highly improbable) unfortunate case that there are no contiguous VAs on every reallocation, this method still has to move a quadratic number of PTEs, but for the given example of growing to 1M, assuming 4K pages that's only 256 PTEs in total - and 1 + 2 + 3 + ... 256 is 32896. Assuming each PTE is 4 bytes, that gives 131584 total bytes moved, in the pathologically worse case.

      And if you’re lucky the OS’s virtual memory system will do some magic with page tables to make the copying cheap. But still, it’s a lot of churn.

      There is no actual copying of data, and as the numbers show, a little over 128K for zero-copy reallocations via VM is still 16x less than the 2M of a doubling, copying buffer.

      Thus, a better strategy could be allocate-copy-free with doubling size for small buffers, and resizing in page-sized increments allowing realloc() to do zero-copy via VM for large buffers.

      Related links:

      http://stackoverflow.com/questions/16765389/is-it-true-that-modern-os-may-skip-copy-when-realloc-is-called

      http://blog.httrack.com/blog/2014/04/05/a-story-of-realloc-and-laziness (discussed previously at https://news.ycombinator.com/item?id=7541004 )

    • FooBarWidgetMar 2017

      Because that is not portable and/or has performance problems.

      I'm not kidding you. I know the conventional wisdom is that a rename is enough. It is not. Depending on the filesystem, you may have to fsync() the directory entry too, or fsync the parent directory entry too. Or on other filesystems, don't do these because doing these may cause problems. And do all this in the right order, because if you get it slightly wrong then it doesn't do what you want in the event of a crash.

      The problem is maddening. There is an article out there that explains all this in much more detail. I think it is this one but I don't quite remember whether it is the same as the one I read: http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/
      The performance problem comes from the fact that you need two fscyncs.

    • sbierwagenDec 2016

      fsync() has never been as reliable as the name implies, since flushing the disk cache kills performance system-wide. Fuzziness on what fsync does has... side effects: https://danluu.com/file-consistency/ http://blog.httrack.com/blog/2013/11/15/everything-you-always-wanted-to-know-about-fsync/

      Filesystems optimized for flash, and for battery-backed systems in general, (laptops, phones) have some history: https://en.wikipedia.org/wiki/Flash_file_system

    • acconstaJan 2016

      For large allocations, realloc can remap virtual memory instead of doing a naive copy:

      http://blog.httrack.com/blog/2014/04/05/a-story-of-realloc-and-laziness/

    • js2Apr 2016

      Unwinding under Android, especially from JNI is also a mess.

      http://blog.httrack.com/blog/2013/08/23/catching-posix-signals-on-android/

    • xrocheDec 2015

      Yup, I reported the same issue a year ago (http://blog.httrack.com/blog/2014/08/31/i-found-a-bug-in-strncat/)

    Related

    Facebook Engineeringcode.facebook.com552 people

    Relicensing React, Jest, Flow, and Immutable.js

    Facebook Engineering
    Company · last shared 2021
    mazzo.limazzo.li35 people

    How fast are Linux pipes anyway?

    mazzo.li
    Personal · last shared 2026
    Joe Damatotimetobleed.com39 people

    American Express fails miserably at basic security

    Joe Damato
    Personal · last shared 2022
    Flickr Code Blogcode.flickr.net102 people

    Flickr – A Year Without a Byte

    Flickr Code Blog
    Company · last shared 2026
    Chris Wellonsnullprogram.com295 people

    Why Aren't There C Conferences?

    Chris Wellons
    Personal · last shared 2026
    Rust Blogblog.rust-lang.org533 people

    Announcing Rust 1.0

    Rust Blog
    Company · last shared 2026
    LLVM Blogblog.llvm.org226 people

    Clang Is Now Used to Build Chrome for Windows

    LLVM Blog
    Company · last shared 2026
    John Regehrblog.regehr.org401 people

    Teaching C

    John Regehr
    Personal · last shared 2026