Our great sponsors
-
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.
[1]: https://ziglang.org/
-
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 (https://sciter.com) I am solving this by callback functions:
typedef void string_receiver(const char* s, size_t slen, void* tag);
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.