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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: A glib-like multi-platform C library

48 点作者 danny0z大约 3 年前

3 条评论

camel-cdr大约 3 年前
Whenever I see such libraries, the first thing I check out is their PRNG implementation, and this one must be the worst I&#x27;ve seen so far. (The rest of the library is probably quite good, I&#x27;m just talking about the PRNG part)<p>The library has one PRNG, and it is the following:<p><pre><code> tb_spinlock_enter(&amp;g_lock); g_value = (g_value * 10807 + 1) &amp; 0xffffffff; tb_spinlock_leave(&amp;g_lock); </code></pre> Using this is literally worse than using the rand reference implementation.<p>Also, tb_random_range uses a biased and slow implementation with modulo. (see <a href="https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html" rel="nofollow">https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html</a> for the proper way to do this)<p>I might look into adding a proper PRNG implementation, but I&#x27;ll recommend a few resources:<p>A lesson of what not to do: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;LDPMpc-ENqY" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;LDPMpc-ENqY</a> (&quot;rand() Considered Harmful&quot;) Some good modern PRNGs: <a href="https:&#x2F;&#x2F;www.pcg-random.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.pcg-random.org&#x2F;</a>, <a href="https:&#x2F;&#x2F;prng.di.unimi.it&#x2F;" rel="nofollow">https:&#x2F;&#x2F;prng.di.unimi.it&#x2F;</a>, <a href="https:&#x2F;&#x2F;romu-random.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;romu-random.org&#x2F;</a> Generating random numbers in a specific range: <a href="https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html" rel="nofollow">https:&#x2F;&#x2F;www.pcg-random.org&#x2F;posts&#x2F;bounded-rands.html</a>
Rochus大约 3 年前
Looks like a really interesting set of libraries (<a href="https:&#x2F;&#x2F;github.com&#x2F;tboox" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tboox</a>), available under Apache 2 license; also xmake looks interesting; definitely worth a closer look; thanks for sharing.
评论 #31247147 未加载
评论 #31247319 未加载
nextaccountic大约 3 年前
How does the memory library detect use after free?