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

Pages: 1-

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 11:15

Besides reference counted smart pointers the only thing I can think of is RAII.

Name: Anonymous 2014-05-10 11:21

>>2
But what about shit like

blabla(...) {
x = new Foo()
...
return &x.justAField;
// x is freed but we've returned a pointer to one of its fields
}

Name: Anonymous 2014-05-10 11:24

free() is for losers, real men use exit() to free memory

Name: Anonymous 2014-05-10 12:27

Just store all your variables directly in registers.

Name: Anonymous 2014-05-10 12:42

>>3
That is simple, don't do that.

Name: Anonymous 2014-05-10 13:17

But how about closure, how do you manually manage free variable with god knows how long extent?

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.

Name: Anonymous 2014-05-10 17:05

RIGHT TIGHT MY ANUS

Name: Anonymous 2014-05-10 17:54

>>8
Okay thanks.

Name: Anonymous 2016-07-11 5:27

(stopping the dubsfaggot from dubsbumping)

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