User: Password:
|
|
Subscribe / Log in / New account

allocation in C

allocation in C

Posted Jun 17, 2010 16:02 UTC (Thu) by tialaramex (subscriber, #21167)
In reply to: Pauses by nix
Parent article: The Managed Runtime Initiative

Speaking about the largest C project I work on...

In some places the reason I don't use a GC is because I'm lazy and there wasn't one sat there ready to go. It is possible that I should learn to use the Boehm GC in these cases and that I should evangelise its use.

But in a lot of places it's because it's because the code's on the critical path. I don't see a GC (and particularly one you admit is "computationally expensive") buying us more than it costs in these codepaths. This is optimised code, where people have chosen the algorithms very carefully and read the latest papers, and run benchmarks to find good parameters and done all that good stuff. And we already have (by the nature of the system) an insatiable appetite for RAM so we certainly don't want to make that any worse.

Perhaps a better goal is to stop using C at all for the "lazy" code. I probably spend as little as 30% of my programming time writing C these days anyway, maybe it should be less than 10%. Java for example seems to work well enough, it's slow and it wastes a lot of RAM, and it's missing a bunch of features I like, but it works well enough. Probably a lot of my "lazy" code could be Java, more than already is.


(Log in to post comments)

allocation in C

Posted Jun 20, 2010 20:13 UTC (Sun) by nix (subscriber, #2304) [Link]

In some places the reason I don't use a GC is because I'm lazy and there wasn't one sat there ready to go. It is possible that I should learn to use the Boehm GC in these cases and that I should evangelise its use.
Since using the boehm GC in its simplest form consists of including one header and instantly all your malloc()s are garbage-collected, that's not hard. (You don't need to take the free()s out, but they're no longer *necessary*, merely hints that this block no longer needs to be scanned for possible pointers.)

But yes, avoiding C for the boring stuff is probably best. Embed a better language (or embed the C in a better language) and use that, and get GC for free :)

allocation in C

Posted Jun 21, 2010 0:33 UTC (Mon) by khc (guest, #45209) [Link]

Or with LD_PRELOAD ;-) It's hard to decide which one is simpler though.

allocation in C

Posted Jun 21, 2010 20:54 UTC (Mon) by nix (subscriber, #2304) [Link]

I suppose it depends if you have the source to all the bits or not. If you do, using LD_PRELOAD would be just icky. If you don't, it's unavoidable.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds