memory-address

Why do two functions have the same address?

青春壹個敷衍的年華 提交于 2019-11-27 09:43:22
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 any way, so it produces same function. @Mark's answer and comments on this are valuable. :-) Mark Ransom

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

只谈情不闲聊 提交于 2019-11-27 08:42:48
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? Try this http://www.eqware.net/Articles/CapturingProcessMemoryUsageUnderLinux/ It can parse the pagemap for you, for example, if the virtual

How do 8-bit and 16-bit processors access more RAM with two registers?

依然范特西╮ 提交于 2019-11-27 07:57:49
问题 Something that has always confused me is how 8-bit computers access more than 256 bytes of RAM. I know that it must use two registers, but can any one show me an example of what this would look like in assembly code? Like: mov a, [x] ??? 回答1: Let's imagine we have LOWER and HIGHER 8bit half of the address in registers L and H. For example, we want to read byte from address 32770 dec = 8002 hex. mov l, 02h ;lower byte of address mov h, 80h ;higher byte of address mov a, [hl] ;a <-- [h*256 + l]

C++ Standard On The Address of Inherited Members

空扰寡人 提交于 2019-11-27 06:35:10
问题 Does the C++ standard say anything on the address of inherited members? For example if I inherit an int member or a non - virtual method, does it say anything about its address, or a virtual member: if I dont overide it, if I do? The constructor, if I use a previous constructor? Operators, overloaded operators, template members? Does it say anything about these things? 回答1: Standard, section 1.8 is about the C++ object model. It doesn't say much: the object is a region of memory (but it may

memory address positive or negative value in c?

陌路散爱 提交于 2019-11-27 05:48:20
问题 in c, i tried to print out address of variable and address of some function. I got one is negative value, the other is positive value. My question is: why does C not represent in all negative or all positive value? Here is my code: int foo() { return 0; } int main() { int a; printf("%d\n",&a); printf("%d\n",foo); return 0; } Here is result: -1075908992 134513684 回答1: Memory addresses should not be interpreted as signed integers in that way. The sign of the number depends on the highest bit

Difference between logical addresses, and physical addresses?

白昼怎懂夜的黑 提交于 2019-11-27 05:04:42
问题 I am reading Operating Systems Concept and I am on the 8th chapter! However I could use some clarification, or reassurance that my understanding is correct. Logical Addresses: Logical addresses are generated by the CPU, according to the book. What exactly does this mean? (In an execute-generated address system..) I assume when code is compiled for a program, the program has no idea where the code will be loaded in memory. All the compiler does is set up a general sketch of the program layout

both asterisk and ampersand in a parameter c++

坚强是说给别人听的谎言 提交于 2019-11-27 04:37:17
问题 I am reading a book about Binary Search Tree and something weird came up. class BST { public: void insert(const Comparable & item) private: BinaryNode *root; struct BinaryNode { Comparable element; BinaryNode *left; BinaryNode *right; BinaryNode(const Comparable & theElement, BinaryNode *lt, BinaryNode *rt) : element(theElement), left(lt), right(rt) {} } void insert(const Comparable & item, BinaryNode * & t) const; }; The private insert function is helper function for public insert function,

Why is the address of this volatile variable always at 1?

梦想的初衷 提交于 2019-11-27 04:29:44
问题 I wanted to inspect the address of my variable volatile int clock; cout << &clock; But it always says that x is at address 1. Am i doing something wrong?? 回答1: iostreams will cast most pointers to void * for display - but no conversion exists for volatile pointers. As such C++ falls back to the implicit cast to bool . Cast to void* explicitly if you want to print the address: std::cout << (void*)&clock; 回答2: There's an operator<< for const void* , but there's no operator<< for volatile void*

Is the address of an object fixed during its life cycle?

半腔热情 提交于 2019-11-27 03:26:19
问题 Is the address of an object constant during its life cycle or can it change? I just thought address of an object never changes. Is it JVM dependent? I Haven't found any clear spec. 回答1: The address of an object in java is not fixed; rather, it may change (subjected to conditions). This is because normally objects are allocated in eden space. Then they move to survivor space, then also to the old generation space if they survived some garbage collection cycles. So it does change. But if the

Reference as key in swift dictionary

情到浓时终转凉″ 提交于 2019-11-27 03:17:27
问题 Dictionary key requires Hashable conformance: class Test {} var dictionary = [Test: String]() // Type 'Test' dies not conform to protocol 'Hashable' class Test: NSObject {} var dictionary = [Test: String]() // Works How to get address of pure Swift class instance to use as hashValue ? 回答1: Equality can be implemented as object identity, i.e. a == b iff a and b refer to the same instance of the class, and the hash value can be build from the ObjectIdentifier (which is the same for identical