memory-address

Why do two functions have the same address?

心已入冬 提交于 2019-11-26 17:52:19
问题 Consider this function template: template<typename T> unsigned long f(void *) { return 0;} Now, I print the addresses of f<A> and f<B> as: std::cout << (void*)f<A> << std::endl; std::cout << (void*)f<B> << std::endl; Why do they print the same address if compiled in MSVS10? Are they not two different functions and therefore should print different addresses? Updated: I realized that on ideone, it prints the different address. MSVS10 optimizes the code, as the function doesn't depend on T in

How to decode /proc/pid/pagemap entries in Linux?

余生颓废 提交于 2019-11-26 17:46:24
问题 I am trying to decipher how to use /proc/pid/pagemap to get the physical address of a given set of pages. Suppose from the /proc/pid/maps, I get the virtual address afa2d000-afa42000 which corresponds to the heap. My question is how do I use this info to traverse the pagemap file and find the physical page frames correspond to the address afa2d000-afa42000. The /proc/pid/pagemap entry is in binary format. Is there any tools to help parsing of this file? 回答1: Try this http://www.eqware.net

Disable randomization of memory addresses

二次信任 提交于 2019-11-26 12:55:25
问题 I\'m trying to debug a binary that uses a lot of pointers. Sometimes for seeing output quickly to figure out errors, I print out the address of objects and their corresponding values, however, the object addresses are randomized and this defeats the purpose of this quick check up. Is there a way to disable this temporarily/permanently so that I get the same values every time I run the program. Oops. OS is Linux fsttcs1 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 2011 x86_64 GNU

Address of an array

孤街浪徒 提交于 2019-11-26 12:24:15
int t[10]; int * u = t; cout << t << " " << &t << endl; cout << u << " " << &u << endl; Output: 0045FB88 0045FB88 0045FB88 0045FB7C The output for u makes sense. I understand that t and &t[0] should have the same value, but how come &t is also the same? What does &t actually mean? When t is used on its own in the expression, an array-to-pointer conversion takes place, this produces a pointer to the first element of the array. When t is used as the argument of the & operator, no such conversion takes place. The & then explicitly takes the address of t (the array). &t is a pointer to the array

Memory address of variables in Java

荒凉一梦 提交于 2019-11-26 11:11:43
Please take a look at the picture below. When we create an object in java with the new keyword, we are getting a memory address from the OS. When we write out.println(objName) we can see a "special" string as output. My questions are: What is this output? If it is memory address which given by OS to us: a) How can I convert this string to binary? b) How can I get one integer variables address? Brian Agnew That is the class name and System.identityHashCode() separated by the '@' character. What the identity hash code represents is implementation-specific. It often is the initial memory address

How to print variable addresses in C?

喜你入骨 提交于 2019-11-26 10:44:23
问题 When i run this code. #include <stdio.h> void moo(int a, int *b); int main() { int x; int *y; x = 1; y = &x; printf(\"Address of x = %d, value of x = %d\\n\", &x, x); printf(\"Address of y = &d, value of y = %d, value of *y = %d\\n\", &y, y, *y); moo(9, y); } void moo(int a, int *b) { printf(\"Address of a = %d, value of a = %d\\n\", &a, a); printf(\"Address of b = %d, value of b = %d, value of *b = %d\\n\", &b, b, *b); } I keep getting this error in my compiler. /Volumes/MY USB/C Programming

Basic use of immediates vs. square brackets in YASM/NASM x86 assembly

陌路散爱 提交于 2019-11-26 09:43:20
问题 Suppose I have the following declared: section .bss buffer resb 1 And these instructions follow in section .text : mov al, 5 ; mov-immediate mov [buffer], al ; store mov bl, [buffer] ; load mov cl, buffer ; mov-immediate? Am I correct in understanding that bl will contain the value 5, and cl will contain the memory address of the variable buffer ? I am confused about the differences between moving an immediate into a register, moving a register into an immediate (what goes in, the data or the

What exactly is a C pointer if not a memory address?

半城伤御伤魂 提交于 2019-11-26 09:30:00
In a reputable source about C, the following information is given after discussing the & operator: ... It's a bit unfortunate that the terminology [address of] remains, because it confuses those who don't know what addresses are about, and misleads those who do: thinking about pointers as if they were addresses usually leads to grief... Other materials I have read (from equally reputable sources, I would say) have always unabashedly referred to pointers and the & operator as giving memory addresses. I would love to keep searching for the actuality of the matter, but it is kind of difficult

Swift, Strings and Memory Addresses

半腔热情 提交于 2019-11-26 09:13:26
问题 There is something I am not understanding about how Swift manages memory address of String(s) 1. Reference types Here foo and boo are 2 pointers to the same memory location . class Foo { } let foo = Foo() let boo = foo unsafeAddressOf(foo) // \"UnsafePointer(0x7FCD13719BE0)\" unsafeAddressOf(boo) // \"UnsafePointer(0x7FCD13719BE0)\" Good. 2. Value types let word0 = \"hello\" let word1 = word0 Now word0 and word1 are value types but here the copy on write mechanism is involved. [...] However,

Why in 64bit the virtual address are 4 bits short (48bit long) compared with the physical address (52 bit long)?

北战南征 提交于 2019-11-26 08:38:58
In the book "Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture" I read: Each virtual 64-bit address (e.g., ones we are using in our programs) consists of several fields. The address itself is in fact only 48 bits wide; it is sign-extended to a 64-bit canonical address. Its characteristic is that its 17 left bits are equal. If the condition is not satisfied, the address gets rejected immediately when used. Then 48 bits of virtual address are transformed into 52 bits of physical address with the help of special tables. Why is the difference in 4 bits between the