i was debugging a program in two terminals by giving different input,but at on particular i saw this in one terminal
ins (ptr=0x0, key=1, upKey=0xbffff308, newnode=0xbffff30c)
and in another terminal
ins (ptr=0x0, key=1, upKey=0xbffff308, newnode=0xbffff30c)
where ins function is
ins(struct node *ptr, int key, int *upKey,struct node **newnode)
how can the same memory location be allocated to a pointer. and i am running the same program on two different terminals...with different inputs
The basic memory allocation function is malloc(). Its function prototype is: (void *) malloc(size_t numbytes); What this means is that it takes a single argument that is the number of bytes you want to allocate (size_t is usually the same as unsigned int), and it returns a pointer to that new memory space.
Pointer Arithmetic and Array Indicies As declared and initialized to a memory space, pointers point to the base, the first element, of that space.
delete and free() in C++ In C++, the delete operator should only be used either for the pointers pointing to the memory allocated using new operator or for a NULL pointer, and free() should only be used either for the pointers pointing to the memory allocated using malloc() or for a NULL pointer. It is an operator.
Memory is allocated when a pointer is defined. A reference however, is a name alias & hence no memory is allocated for it( Is it correct? ). 2. Reference is bound to be initialized at the time of definition because, a reference is implemented with a constant pointer & hence cannot be made to point to the other object.
The memory addresses you are looking at are virtual addresses. Those addresses are then translated by the processor to physical addresses. This is the basis of all modern operating systems. Each process thinks it owns the entire address space (4GB in the case of a 32 bit machine, a lot more in the case of a 64bit machine). When a process accesses memory that has yet to be allocated to it a page fault is generated by the CPU. The OS can then handle that invalid memory access in one of several ways; one common way is a segmentation fault.
With virtual memory, every program running on a system acts as though it has the computer's entire address space to itself. However, every time a pointer is dereferenced, a special piece of hardware translates from the pointer's purported address (its virtual address) to some other location in memory where the data actually lives (the physical address). The operating system is built to manage and move the regions of memory to which virtual addresses are mapped, so if one program dereferences some address A it will map to a different location in physical memory than you would get if you dereferenced address A in a different process. In fact, any number of programs can all claim to use address A without hassle, since these virtual addresses all resolve to different physical addresses on the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With