The pervasive effects of C's malloc() and free() on C APIs

This page summarizes the projects mentioned and recommended in the original post on

Our great sponsors
  • Scout APM - Truly a developer’s best friend
  • - Download’s Tech Salary Report
  • SonarQube - Static code analysis for 29 languages.
  • zig

    General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

    > This is unavoidable in any language that (supports dynamic memory allocation and) moves dynamic memory allocation into a library.

    Not necessarily. The Zig[1] standard library forces callers to provide at runtime an allocator to each data structure or function that allocates. Freeing is then handled either by running deinit() on the datastructure returned (a standard convention), or, if the function returns a pointer, using the same allocator you passed in to free the returned buffer. C's problem here is it doesn't have namespaces or member functions, so there's a mix of conventions for what the freeing function should be called.

    C++ allows this as well for standard library containers, although I've rarely seen it used.

    > Also, say a DLL function returns a char pointer containing a string. How would you know whether to call free or delete on it? Or, maybe, the equivalent of free in Frob, the language that DLL happens to be written in?

    I have to concede this one. I can't see a way out of this other than documentation.


  • sciter

    Sciter: the Embeddable HTML/CSS/JS engine for modern UI development

    Do we need to free the string? And if "yes" then how? It is not realistic to provide free** for each such API function...

    In Sciter API ( I am solving this by callback functions:

        typedef void string_receiver(const char* s, size_t slen, void* tag);

  • Scout APM

    Truly a developer’s best friend. Scout APM is great for developers who want to find and fix performance issues in their applications. With Scout, we'll take care of the bugs so you can focus on building great things 🚀.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts