TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Malloc() and free() are a bad API (2022)

3 pointsby moutansosover 1 year ago

3 comments

kelthanover 1 year ago
The one thing to keep in mind when reading this article is that the malloc&#x2F;free API was built when many of the issues that are identified in this article (alignment, sizing, etc.) were not issues. Until the early 80&#x27;s computer memory was the limiting cost factor for most machines, and the memory models were fairly simple. Alignment to something like a page boundary was something that was completely unreasonable&#x2F;unfathomable, since wasting that much RAM would have been extraordinarily wasteful.<p>Modern CPUs have more memory built in to L1, L2, and L3 caches than most computers had in total working memory until memory started getting cheap.<p>I agree with the author that has lead to some &quot;sharp edges&quot; for the API, but that is a normal growth pattern. I&#x27;m not saying that the API doesn&#x27;t have to change, but I did want to make sure that people understand that the creators of the old APIs were not stupid, they just faced different constraints than we do now. And that led to API &quot;shapes&quot; that may be surprising and frustrating to use now, but made perfectly good sense at the time.
pjmlpover 1 year ago
It starts already that contrary to most systems programming languages that predated C, the only way is to do math with sizeof instead of specifying types, and when arrays decay into pointers many get it wrong.<p>So then there is always the helpful macro, doing what should have been a language feature in first place.
aimonster2over 1 year ago
They are fine for good programmers. Programmers like me need guard rails though.