C++ Some Stack questions -


let me start saying have read this tutorial , have read this question. questions are:

  1. how big can stack ? processor/architecture/compiler dependent ?

  2. is there way know how memory available function/class stack , how being used in order avoid overflows ?

  3. using modern compilers (say gcc 4.5) on modern computer (say 6 gb ram), need worry stack overflows or thing of past ?

  4. is actual stack memory physically on ram or on cpu cache(s) ?

  5. how faster stack memory access , read compared heap access , read ? realize times pc specific, ratio enough.

  6. i've read not advisable allocate big vars/objects on stack. how big ? this question here given answer of 1mb thread in win32. how thread in linux amd64 ?

i apologize if questions have been asked , answered already, link welcome !

  1. yes, limit on stack size varies, if care you're probably doing wrong.
  2. generally no can't information how memory available program. if obtain such information, stale before use it.
  3. if share access data across threads, yes need serialize access unless they're strictly read-only.
  4. you can pass address of stack-allocated object thread, in case (again) have serialize unless access strictly read-only.
  5. you can overflow stack on modern machine lots of memory. stack limited small fraction of overall memory (e.g., 4 mb).
  6. the stack allocated system memory, used enough @ least top page or 2 typically in cache @ given time.
  7. being part of stack vs. heap makes no direct difference access speed -- 2 typically reside in identical memory chips, , @ different addresses in same memory chip. main difference stack contiguous , heavily used, top few pages in cache. heap-based memory typically fragmented, there's greater chance of needing data that's not in cache.
  8. little has changed respect maximum size of object should allocate on stack. if stack can larger, there's little reason allocate huge objects there.
  9. the primary way avoid memory leaks in c++ raii (aka sbrm, stack-based resource management).
  10. smart pointers large subject in themselves, , boost provides several kinds. in experience, collections make bigger difference, basic idea largely same either way: relieve programmer of keeping track of every circumstance when particular object can used or should freed.

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -