Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I'm willing to admit that GC is shit

Name: Anonymous 2014-05-10 11:02

/prog/, I've been giving some thought to the whole "GC is shit" thing and I want to try a different view. You see, I've been using only languages with automatic memory management lately, and they are inherently limiting. So my question is: what's the fastest way to learn the techniques of writing memory-safe programs in languages without GC?

There must be a set of rules, and it's okay if those rules are quite complex and take practice to master, but there must be a set of rules that, once learned, lets you write programs that are just as safe as in the auto-land but much more efficient. How can I learn those rules?

Name: Anonymous 2014-05-10 16:17

lets you write programs that are just as safe as in the auto-land but much more efficient.

The rules are simple, but checking that the rules are followed is nontrivial in a very large project.

1. Thou shalt not refer to a variable past its extent.
2. Thou shalt not loose a reference to an object on the heap before calling free.
3. Thou shalt not use an object after it has been freed. Thou shalt not call free on the same object more than once.
4. Thou shalt not use an index on an array that it outside its bounds.
5. Thou shalt not forget to leave a null terminator at the end of your strings.
6. Thou shalt remember to keep the null terminator within the bounds of the memory allocated for the string.

etc etc. Once you can code securely, then comes efficiency

7. Thou shalt call malloc and free frequently in a loop if stack allocation can be used instead.
8. Thou shalt organize data structures to increase cache coherency.
9. Thou shalt right tight loops with unusual flow control and high numbers of branches manually in assembly.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List