TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The history of Unix's confusing set of low-level ways to allocate memory (2018)

97 点作者 jaytaylor超过 3 年前

10 条评论

kinghajj超过 3 年前
This brought back memories from college, when I tried to write my own C memory allocator. It was decidedly simple and extremely inefficient (pretty sure it used linked lists...), but after much hacking I did eventually get it to work with some small CLI programs using the LD_PRELOAD trick... but when I tried launching Gimp, the inefficiency quickly became apparent. I think eventually the splash screen did come up, but I never gave it enough time fully to start!<p>My implementation used brk()&#x2F;sbrk() exclusively, but I thought about re-implementing with mmap(). Hell, maybe I can try to write an allocator in Rust and expose a C-compatible interface.
评论 #29103246 未加载
anyfoo超过 3 年前
This sounds so ancient, but I clearly remember seeing the sbrk() system call happening a lot when strace&#x27;ing processes on Linux, so it can&#x27;t be much more than 20 years ago, or maybe much less even. When did allocators on Linux stop doing that? glibc?<p>EDIT: Never mind, the article answers that eventually, it&#x27;s still used apparently: &quot;I know that GNU libc does use brk() based allocation for programs that only make small allocations, for example &#x2F;usr&#x2F;bin&#x2F;echo.&quot;
评论 #29090794 未加载
panic超过 3 年前
It&#x27;s worth noting that WebAssembly, at least for the moment, only supports a single brk&#x2F;sbrk-style growable heap -- allocators targeting the web can&#x27;t use any of the mmap tricks.
评论 #29091058 未加载
kazinator超过 3 年前
So much amusing past tense there, given that Linux has a sbrk() function and Glibc cheerfully uses it for small allocations in single-threaded programs. This stuff is today.
评论 #29092161 未加载
blippage超过 3 年前
Tangentially, libraries for microcontrollers (e.g. nanolib) will typically use sbrk(). To port the library to a new architecture for the memory stuff you usually implement sbrk() yourself, and this will be sufficient for malloc and friends to compile
userbinator超过 3 年前
On the other hand, as far as I know, there was never the concept of a &quot;brk&quot; in the DOS&#x2F;Windows world; in DOS, by default programs got all memory (no virtual memory, all physical), and there was a set of malloc&#x2F;free&#x2F;realloc-ish functions for TSRs and other &quot;advanced&quot; techniques. DOS-based Windows memory allocation goes through DPMI which again provides similar functionality to malloc&#x2F;free&#x2F;realloc, as well as mmap. NT-based Windows is similar but without the DPMI.
评论 #29091337 未加载
gtirloni超过 3 年前
Tangential question: Is anything considered state-of-the-art in terms of replacing POSIX?
评论 #29090018 未加载
guerrilla超过 3 年前
I&#x27;m not sure what&#x27;s supposed to be confusing here but one thing I don&#x27;t know is why it was called the heap. Did they use heap data structures or something?
评论 #29090140 未加载
评论 #29091086 未加载
throwawaylinux超过 3 年前
There is another way unix allocates memory, and that is with automatically growing regions that are used to allocate program stack.
anaisbetts超过 3 年前
This is pretty typical in nearly every modern operating system - the kernel hands out large chunks of memory and the user-mode side actually does the accounting to implement malloc&#x2F;free. Memory management in NT is also done in usermode (i.e. in-process)