memory-address

Printing addresses of Perl object methods? (for redefining Perl class methods)

淺唱寂寞╮ 提交于 2020-01-15 04:56:06
问题 I saw How can I redefine Perl class methods?, so I wanted to understand better how it works through an example. (Related: How do I reference methods? - PerlMonks) If I have an object $obj which is an instance of some Class which has Class::method , then $obj also has $obj->method ; I assume the simplified memory layout in that case would look something like this (tables made in LaTeX Table Generator; for the below one, src here): ... that is, at (say) address 0x1000 we have the $obj->method ,

Java: How to store and retrieve memory address like in C++

泪湿孤枕 提交于 2020-01-14 10:23:20
问题 I come from a C++ background. In C++ I can store a memory adress which I just new'd in a global array and re-use it later. For example, say I have two classes X, Y and I create two objects x, y. The global array StoreAddresses[2] is defined as: uint32_t StoreAddresses[2]; I write: X * x = new X(); Y * y = new Y(); StoreAdresses[0] = (uint32t *) x; //for example, 0x12345678 StoreAdresses[1] = (uint32t *) y; //for example, 0x12345698 Anywhere in my program, I can retrieve the data written in

How to apply a mask to a const void* address?

不想你离开。 提交于 2020-01-14 10:19:26
问题 I work on an embedded target and want to define memory pools. Memory addresses are represented as void* . However in a particular case, those addresses are cached and I want to uncache them to get directly the "real" hardware address. I want to define the address of the beginning of memory_area (which is just a marker): #define UNCACHE_MASK 0xABCDEF12UL // Value of the mask to apply extern uint32_t memory_area; // Global, defined somewhere else const void * virtual_address = &memory_area; //

How to not get different memory addresses for elements in a Realm List?

巧了我就是萌 提交于 2020-01-14 03:40:12
问题 If I iterate over an array in Swift with: for element in array { ... } and place a breakpoint inside the for statement and look at the address of the object stored as element, than I get a different address than if I let the debugger run the expression: array.first There is only one element in the array. So, why do I not get the same address? Here is a screenshot of the debugger in action: I am iterating over the attachments of a mail. When I debugged, the mail only had one attachment. The

Kernel sys_call_table address does not match address specified in system.map

一笑奈何 提交于 2020-01-13 17:11:45
问题 I am trying to brush up on C so I have been playing around with the linux kernel's system call table (on 3.13.0-32-generic). I found a resource online that searches for the system call table with the following function which I load into the kernel in an LKM: static uint64_t **aquire_sys_call_table(void) { uint64_t offset = PAGE_OFFSET; uint64_t **sct; while (offset < ULLONG_MAX) { sct = (uint64_t **)offset; if (sct[__NR_close] == (uint64_t *) sys_close) { printk("\nsys_call_table found at

Kernel sys_call_table address does not match address specified in system.map

隐身守侯 提交于 2020-01-13 17:11:27
问题 I am trying to brush up on C so I have been playing around with the linux kernel's system call table (on 3.13.0-32-generic). I found a resource online that searches for the system call table with the following function which I load into the kernel in an LKM: static uint64_t **aquire_sys_call_table(void) { uint64_t offset = PAGE_OFFSET; uint64_t **sct; while (offset < ULLONG_MAX) { sct = (uint64_t **)offset; if (sct[__NR_close] == (uint64_t *) sys_close) { printk("\nsys_call_table found at

Assign a value to a specific address

跟風遠走 提交于 2020-01-13 11:23:12
问题 It is an interview question, which I came across at a book for interviews, and later in an interview. The question is How to assign value (say 0 ) to an address (say 0x12345678 ). My best try for this question (after a long time after the interview) is An address is a number which can be stored in a pointer, and we can assign a value to the address by a pointer, the value of which is the address, like: int* p = 0x12345678; *p = 0; However, it is not possible on a system with memory management

Is the address of a reference to a dereferenced pointer the same as the address of the pointer?

拈花ヽ惹草 提交于 2020-01-12 06:58:11
问题 In C++, is the address of a reference to a dereferenced pointer guaranteed to be the same as the address of the pointer? Or, written in code, is the following assertion guaranteed to always hold true? SomeType *ptr = someAddress; SomeType &ref = *ptr; assert(&ref == ptr); 回答1: Yes, that is correct and will always be true. Reference is nothing but an Alias of the type which it is referring to. It does not have a separate existence, it is always tied up to the one it is referring. 回答2: Yes,

& in function declaration return type

自闭症网瘾萝莉.ら 提交于 2020-01-09 11:55:10
问题 What does the & mean in the following? class Something { public: int m_nValue; const int& GetValue() const { return m_nValue; } int& GetValue() { return m_nValue; } }; This code is taken from here. 回答1: It means return value by reference: int& GetValue() ^ Means returns a reference of int Like int i = 10; int& GetValue() { int &j = i; return j; } j is a reference of i , a global variable. Note: In C++ you have three kinds of variables: Value variable for example int i = 10 . Reference

x86-64 address calculation in 64bit mode with 32-bit address-size

时光怂恿深爱的人放手 提交于 2020-01-07 02:21:02
问题 I read Intel manual about address calculation in 64 bit mode. Suppose we have 64 bit mode, default address size is 64 bit. Suppose also that instruction in question is preceded by address size override prefix, so address size becomes 32 bit. Now, imagine that instruction encodes memory operand with address specified by register number 0 (rax/eax/ax ...). Now the thing that I don't fully understand, whether CPU looks only at eax value and internally zero-extends it to form "native" 64 bit