Live data from Hacker News

Giving C a superpower: custom header file (safe_c.h)

hwisnu.bearblog.dev

271–277 of 277 posts

Re: Giving C a superpower: custom header file (safe_c.h)

#271

Earlier quoted context omitted.

I think that a blanket should/shouldn't recommendation for arenas isn't right. Arenas are a tradeoff: Pros: preallocating one arena is likely faster than many smaller allocations. Cons: preallocation is most effective if you can accurately predict usage for the arena; if you can't, then you either overshoot and allocate more memory than you need, or undershoot and have to reallocate which might be less performant tha…

>If you aren't preallocating and just using arenas for to free in a group, then I'm going to say using an arena for stuff that is going to be freed by the OS at program exit is adding complexity for no benefit What makes you think that the program is going to exit anytime soon? Arenas are useful if you want to execute a complex workflow and when it is over just blow away all the memory it accumulated. An HTTP server…

> What makes you think that the program is going to exit anytime soon?

Because freeing memory in multiple exit paths of a short-running program is the definition of the problem he's trying to solve. Read what I posted before you waste everyone's time with another ego-based response where you don't admit you missed that important detail.

I'm well aware of what arenas are and they're an excellent tool for a lot of situations, maybe even most situations, but this isn't one of those situations.

Also be sure to let the authors of grep know their program used by millions of people is a toy program.

Re: Giving C a superpower: custom header file (safe_c.h)

#272

Earlier quoted context omitted.

There are (older) OSes where this is NOT the case. Leaving things un-freed would leak memory after the application has terminated.

Sure. And the rare programmer reading this who is still using that OS knows they're the exception to the rule. To everyone else that fact is irrelevant.

It still matters when you try to keep your components truly portable (aka you're not just targeting the big 3).

Re: Giving C a superpower: custom header file (safe_c.h)

#273
post #179
post #175

Earlier quoted context omitted.

It's the most predictable and has much less overhead than a moving collector.

Only when we forget about the impact of cycle collections, or domino effects stoping the world when there is a cascade of counters reaching zero. The optimisatios needed to improve such scenarions, are akin to a poor man's tracing GC implementation.

I didn't forget. That's predictable. It happens when the application code does something, or stops doing something, as opposed to the moving collector just doing it at random times.

Re: Giving C a superpower: custom header file (safe_c.h)

#274

Earlier quoted context omitted.

Sure. And the rare programmer reading this who is still using that OS knows they're the exception to the rule. To everyone else that fact is irrelevant.

It still matters when you try to keep your components truly portable (aka you're not just targeting the big 3).

Did you read the post you're responding to?

Re: Giving C a superpower: custom header file (safe_c.h)

#275

Earlier quoted context omitted.

MSVC is a C++ compiler toolchain and it does not contain any JavaScript. You're thinking of VSCode, probably, but your comment was an off-topic rant either way.

Microsoft visual studio the IDE (not vs code the electron program) has lots of javascript processes running in the background doing all sorts of things. Also my comment was a single sentence with a single fact so it can't be a rant.

MSVC is also completely different from Visual Studo. It’s OK to say you were wrong. You don’t have to be angry online. I promise!

Re: Giving C a superpower: custom header file (safe_c.h)

#276
post #275

Earlier quoted context omitted.

Microsoft visual studio the IDE (not vs code the electron program) has lots of javascript processes running in the background doing all sorts of things. Also my comment was a single sentence with a single fact so it can't be a rant.

MSVC is also completely different from Visual Studo. It’s OK to say you were wrong. You don’t have to be angry online. I promise!

MSVC is also completely different from Visual Studo

It can and does refer to the IDE first. I'll prove it to your by showing that it's the first result of a search.

https://duckduckgo.com/?q=MSVC&t=ffab&ia=web

https://visualstudio.microsoft.com/vs/features/cplusplus/

It’s OK to say you were wrong. You don’t have to be angry online. I promise!

Seems like projection. Since it's ok to be wrong I guess you'll reply with an apology.

Re: Giving C a superpower: custom header file (safe_c.h)

#277
post #142

This is a great example of how ADTs can be implemented in C by emulating classes, despite the loss in brevity. For the first item on reference counting, batched memory management is a possible alternative that still fits the C style. The use of something like an arena allocator approximates a memory lifetime, which can be a powerful safety tool. When you free the allocator, all pages are freed at once. Not only is th…

> This is a great example of how ADTs can be implemented in C by emulating classes, despite the loss in brevity. I don't see it that way, mostly because ADTs don't require automatic destructors or GC, etc, but also because I never considered a unique/shared pointer type to be an abstract data type > When you free the allocator, all pages are freed at once. Not only is this less error prone, but it can decrease perfor…

> My experience with arenas is that they increase performance at the cost of a little extra memory usage.

ack, thanks! You’re exactly right, I got my words mixed up.

Post reply on HN