Where in memory are my variables stored in C?

You got some of these right, but whoever wrote the questions tricked you on at least one question: global variables ——-> data (correct) static variables ——-> data (correct) constant data types —–> code and/or data. Consider string literals for a situation when a constant itself would be stored in the data segment, and references to … Read more

How are multi-dimensional arrays formatted in memory?

A static two-dimensional array looks like an array of arrays – it’s just laid out contiguously in memory. Arrays are not the same thing as pointers, but because you can often use them pretty much interchangeably it can get confusing sometimes. The compiler keeps track properly, though, which makes everything line up nicely. You do … Read more

How do cache lines work?

If the cache line containing the byte or word you’re loading is not already present in the cache, your CPU will request the 64 bytes that begin at the cache line boundary (the largest address below the one you need that is multiple of 64). Modern PC memory modules transfer 64 bits (8 bytes) at … Read more

How to find Java Heap Size and Memory Used (Linux)?

Each Java process has a pid, which you first need to find with the jps command. Once you have the pid, you can use jstat -gc [insert-pid-here] to find statistics of the behavior of the garbage collected heap. jstat -gccapacity [insert-pid-here] will present information about memory pool generation and space capabilities. jstat -gcutil [insert-pid-here] will … Read more

How do I determine the correct “max-old-space-size” for node.js?

“Old space” is the biggest and most configurable section of V8’s managed (aka garbage-collected) heap (i.e. where the JavaScript objects live), and the –max-old-space-size flag controls its maximum size. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory. If heap memory consumption (i.e. … Read more

What are the dangers when creating a thread with a stack size of 50x the default?

Upon comparing test code with Sam, I determined that we are both right! However, about different things: Accessing memory (reading and writing) is just as fast wherever it is – stack, global or heap. Allocating it, however, is fastest on stack and slowest on heap. It goes like this: stack < global < heap. (allocation … Read more

How dangerous is it to access an array out of bounds?

As far as the ISO C standard (the official definition of the language) is concerned, accessing an array outside its bounds has “undefined behavior“. The literal meaning of this is: behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements A non-normative note … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)