Live data from Hacker News

What every programmer should know about memory (2007)

lwn.net

51–55 of 55 posts

Re: What every programmer should know about memory (2007)

#51
post #14
post #5

there are just three things i wish programmers knew about memory... none of them are especially low-level or require depth of understanding. never dynamically allocate it unless forced. really. never allocate at run-time it unless you are absolutely forced by your algorithm. if you absolutely really must allocate memory on the fly, have a budget so you can do one big up-front allocation and carefully reuse it. even b…

You do know that function stack frames are dynamically allocated (just not from the heap in most C and C++ implementations).

in a sense yes, but its not a realistic way to use the term.

what happens is that the stack is once dynamically allocated up-front when the thread is created and an index into that blob of memory is incremented and decremented as appropriate (stack pointer).

you can call that allocation, and it would be accurate but its not what i meant at all. it also avoids growing your memory consumption and doesn't impact memory budgets no matter how much stack you try and use (you will overflow it instead... and will need to allocate a bigger budget upfront for the stack with a compiler flag)

Re: What every programmer should know about memory (2007)

#52
post #5

there are just three things i wish programmers knew about memory... none of them are especially low-level or require depth of understanding. never dynamically allocate it unless forced. really. never allocate at run-time it unless you are absolutely forced by your algorithm. if you absolutely really must allocate memory on the fly, have a budget so you can do one big up-front allocation and carefully reuse it. even b…

I'll remember that the next time I'm using python.

i'm not sure using a dynamic late scripting language is an excuse for pretending memory is infinite. :)

but yes... i do have frustration from "highly skilled native programmers" who seem to think that memory is a boundless resource and then complain that something like 32GB is a constrained memory environment when it is the exact opposite.

Re: What every programmer should know about memory (2007)

#53
post #30
post #5

there are just three things i wish programmers knew about memory... none of them are especially low-level or require depth of understanding. never dynamically allocate it unless forced. really. never allocate at run-time it unless you are absolutely forced by your algorithm. if you absolutely really must allocate memory on the fly, have a budget so you can do one big up-front allocation and carefully reuse it. even b…

It would help to give reasons why rather than simply commandments. I'll give one: Performance takes a hit with dynamic allocation. Deallocation also has to occur and if you use GC you may experience pauses as this happens. Your GC may vary. The performance inpact of dynamic allocation may of course be completely acceptable when traded against productivity gains.

true. i wasn't just thinking about performance but also budgetting.

using memory as an endless resource without thinking seems to be standard practice rather than something that is considered "sloppy".

there is also the practice involved. run-time allocation is a bit of a golden sledgehammer and a double edged sword... sure you can write code more quickly, but you are also being enabled to write worse code (i.e. leaks). i don't think we should take the power away, but respect it more...

Re: What every programmer should know about memory (2007)

#54
post #45

Earlier quoted context omitted.

I disagree with your judgement about the grammatically of the utterance. And if you've ever written comments about anything, for example, someone's writing or pictures, you'll probably say things like "me in Peru" or "needs revising" or "word is inappropriate"

I would never say, "word is inappropriate". I would say, "This word is inappropriate". It's clearer and there's almost no cost to using a well-formed sentence. Similarly, I find comments where the single word "this" is used as an entire sentence detract from a forum based site. I can talk to u in allthememes! and sms abbreviations, but I chose to save that register for chat and look for something a bit more correct o…

I was on the subway and saw "DON'T LEAN ON DOOR" and remembered this thread.

Your comment about "this" and internet shorthand and memes is not related to your grammaticality judgement, unless you are admitting to conflating "clarity" with "propriety".

Re: What every programmer should know about memory (2007)

#55
post #46
post #44

Earlier quoted context omitted.

I am strongly grammatically sensitive. And although I am not a native English speaker, I claim that the sentence is grammatically correct. It's just a shortened sentence form. Which is often appropriate on forums and similar.

Hmm... I wouldn't have put the period between "form" and "which" in your comment either. Doing so made your last sentence a sentence fragment. What's your native language? Your English appears to be at least very near native.

Yes, I was aware of that.

Dutch, by the way.

Post reply on HN