I always have this confusion,in arm assembly, is the stack a separate memory unit or a partition of the main memory itself? In my understanding,the main memory(RAM) is divided into stack and heap.The stack is pointed by the stack pointer R13 register or sp.From this pointer we can do the stack operations. Also what I understand is that stack stores local variables in high level languages and function calls.How does it translate to assembly? I am not able to find the answers to these questions on google.
5968
Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear explanation of this.  I understand what a stack is. But,    Where and what are they (physically in a real computer's memory)? To what extent are they controlled by the OS or language run-time? What is their scope? What determines the size of each of them? What makes one faster?
18701
Does anyone know of any good tools (I'm looking for IDEs) to write assembly on the Mac. Xcode is a little cumbersome to me.  Also, on the Intel Macs, can I use generic x86 asm?  Or is there a modified instruction set? Any information about post Intel.  Also: I know that on windows, asm can run in an emulated environment created by the OS to let the code think it's running on its own dedicated machine. Does OS X provide the same thing?
97462
This has been something that has bothered me for ages now.  We are all taught in school (at least, I was) that you MUST free every pointer that is allocated.  I'm a bit curious, though, about the real cost of not freeing memory.  In some obvious cases, like when malloc is called inside a loop or part of a thread execution, it's very important to free so there are no memory leaks.  But consider the following two examples:  First, if I have code that's something like this:  int main() {     char *a = malloc(1024);     /* Do some arbitrary stuff with 'a' (no alloc functions) */     return 0; }   What's the real result here?  My thinking is that the process dies and then the heap space is gone anyway so there's no harm in missing the call to free (however, I do recognize the importance of having it anyway for closure, maintainability, and good practice).  Am I right in this thinking?  Second, let's say I have a program that acts a bit like a shell.  Users can declare variables like aaa = 123 and those are stored in some dynamic data structure for later use.  Clearly, it seems obvious that you'd use some solution that will calls some *alloc function (hashmap, linked list, something like that).  For this kind of program, it doesn't make sense to ever free after calling malloc because these variables must be present at all times during the program's execution and there's no good way (that I can see) to implement this with statically allocated space.  Is it bad design to have a bunch of memory that's allocated but only freed as part of the process ending?  If so, what's the alternative?
47546
So recently I've wanted to learn assembly, so I learnt a bit. I put this into nano and saved it as playground.asm. Now I'm wondering, how do I compile and run it? I've already searched everywhere and still cant find it. I'm really curious and there's no point learning a language if you can't even use it.
99970
for some years, I've read that it's a good idea to create a swap partition having the double space of my RAM. does it still apply today? or this isn't needed anymore?  I have a server with 8 GiB of RAM and I need to create a swap partition, and I was wondering if  16 GiB was too much.
84218
During process execution, when the memory map of a process is like so:    This might be a silly question, but what is responsible for reserving the Kernel space in the address space? Are user processes responsible for this? privileged processes? all processes?  From my understanding, the kernel memory space is reserved by the process running but it is only accessible by the CPU when instructed to execute under ring 0. Is this correct ?
45054
What is the difference between the following set of pointers? When do you use each pointer in production code, if at all?  Examples would be appreciated!   scoped_ptr shared_ptr weak_ptr intrusive_ptr   Do you use boost in production code?
13624
One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular.  However, I've also heard it stated many times that although that's not entirely false, the cases where assembler can actually be used to generate more performant code are both extremely rare and require expert knowledge of and experience with assembly.    This question doesn't even get into the fact that assembler instructions will be machine-specific and non-portable, or any of the other aspects of assembler.  There are plenty of good reasons for knowing assembly besides this one, of course, but this is meant to be a specific question soliciting examples and data, not an extended discourse on assembler versus higher-level languages.  Can anyone provide some specific examples of cases where assembly will be faster than well-written C code using a modern compiler, and can you support that claim with profiling evidence?  I am pretty confident these cases exist, but I really want to know exactly how esoteric these cases are, since it seems to be a point of some contention.
36607
I'm using MinGW with GCC 3.4.5 (mingw-special vista r3).  My C application uses a lot of stack so I was wondering is there any way I can tell programatically how much stack is remaining so I can cleanly handle the situation if I find that I'm about to run out.  If not what other ways would you work around the problem of potentially running out of stack space?  I've no idea what size of stack I'll start with so would need to identify that programatically also.
16918
When I run arm-none-eabi-objcopy -O binary add.elf add.bin everything seems to be ok. But, later when I run ls -lh add.bin add.elf this is the output I received:   -rw-r--r-- 1 david david 2,6G nov 23 22:49 add.bin -rwxr-xr-x 1 david david 65K nov 23 22:40 add.elf   this is a huge file. But when I run du -h add.bin the output is:   8,0K    add.bin   What's happening here?  Edit: Output of arm-none-eabi -A -t -x add.bin:    Warning: could not locate 'add.bin'.  reason: Value too large for defined data type   Output of arm-none-eabi -A -t -x add.elf:   section           size         addr .text             0x2c          0x0 .data              0xc   0xa0000000 .ARM.attributes   0x14          0x0 Total             0x4c   Output of du -bh add.bin:   2,6G    add.bin   This is how I fixed it:  Initially when I link the program with the command arm-none-eabi-ld -Tld_script.lds -o add.elf add.o the ld script file ld_script.lds contains this:   SECTIONS {         . = 0x00000000;         .text : {                  * (.text);          }          . = 0xA0000000;  /* RAM starting address */         .data :{                  * (.data);          } }   The above code fills from 0x00000000 to 0xA0000000 with 0s. This error can be solved the following way:   SECTIONS {         . = 0x00000000;         .text : {                  * (.text);          }         flash_sdata = .; /* Start data in flash right after the text */          . = 0xA0000000;  /* RAM starting address */         ram_sdata = .;          /* AT specifies the load addr. of .data section */         .data : AT (flash_sdata) {                  * (.data);          }         ram_edata = .;   /* Address of end of data in RAM */         data_size = ram_edata - ram_sdata; }   And then in the source I added a piece to copy the data from Flash to RAM. Something like this:           @ Copy data to RAM. start:         ldr   r0, =flash_sdata         ldr   r1, =ram_sdata         ldr   r2, =data_size  copy:         ldrb  r4, [r0], #1         strb  r4, [r1], #1         subs  r2, r2, #1         bne   copy    If my English is not too precise, this is the  which helps me to fix the problem. (And a good site for learning ARM embedded programming).
73357
On the discussion of dynamic memory here:   The author states:     A memory block like this can effectively be used as a more flexible array. This approach is actually much more common in real-world C programs. It's also more predictable and flexible than a "variable size array"   The type of memory block he is talking about is as such:  const int size = 5; int * array = calloc(size, sizeof(int));   and then using another pointer to iterate over the array:  int * index = array; for (i = 0; i &lt; size; i++) {     *index = 1; // or whatever value     index++; }   My question is how is this method better than a standard variable sized array like this?:  int array[variable];   or dynamic:  char name[] = "Nick";   The author doesn't really shed much light as to why I should prefer the former method to the latter. Or more specifically: How is it more "predictable and flexible"?
115971
In the context of C++ (not that it matters):  class Foo{     private:         int x[100];     public:         Foo(); }   What I've learnt tells me that if you create an instance of Foo like so:  Foo bar = new Foo();   Then the array x is allocated on the heap, but if you created an instance of Foo like so:  Foo bar;   Then it's created on the stack.  I can't find resources online to confirm this.
86999
Admittedly I don't get it. Say you have a memory with a memory word of length of 1 byte. Why can't you access a 4 byte long variable in a single memory access on an unaligned address(i.e. not divisible by 4), as it's the case with aligned addresses?
59383
Is Kernel space used when Kernel is executing on the behalf of the user program i.e. System Call? Or is it the address space for all the Kernel threads (for example scheduler)?  If it is the first one, than does it mean that normal user program cannot have more than 3GB of memory (if the division is 3GB + 1GB)? Also, in that case how can kernel use High Memory, because to what virtual memory address will the pages from high memory be mapped to, as 1GB of kernel space will be logically mapped?
83496
How does gcc implement stack unrolling for C++ exceptions on linux?  In particular, how does it know which destructors to call when unrolling a frame (i.e., what kind of information is stored and where is it stored)?
65399
if I understand correctly, in the following output produced by free, 3535m is the actual free memory available to applications, only 413m is used, is this correct?  need some clarification on the difference between Mem and -/+ buffers/cache row.   free -m              total       used       free     shared    buffers     cached Mem:          3949       3854         95          0          9       3431 -/+ buffers/cache:        413       3535 Swap:         2047       1322        725
13020
I want to initialize a struct element, split in declaration and initialization. This is what I have:  typedef struct MY_TYPE {   bool flag;   short int value;   double stuff; } MY_TYPE;  void function(void) {   MY_TYPE a;   ...   a = { true, 15, 0.123 } }   Is this the way to declare and initialize a local variable of MY_TYPE in accordance with C programming language standards (C89, C90, C99, C11, etc.)? Or is there anything better or at least working?  Update I ended up having a static initialization element where I set every subelement according to my needs.