Get memory address of member function?

There exists a syntax to get the address of the member function in MSVC (starting from MSVC 2005 IMHO). But it’s pretty tricky. Moreover, the obtained pointer is impossible to cast to other pointer type by conventional means. Though there exists a way to do this nevertheless. Here’s the example: // class declaration class MyClass … Read more

Why does Go forbid taking the address of (&) map member, yet allows (&) slice element?

There is a major difference between slices and maps: Slices are backed by a backing array and maps are not. If a map grows or shrinks a potential pointer to a map element may become a dangling pointer pointing into nowhere (uninitialised memory). The problem here is not “confusion of the user” but that it … Read more

Difference between logical addresses, and physical addresses?

This answer is by no means exhaustive but it may explain it enough to make things click. In virtual memory systems, there is a disconnect between logical and physical addresses. An application can be given a virtual address space of (let’s say) 4G. This is its usable memory and it’s free to use it as … Read more

Access memory address in python

Have a look at ctypes.string_at. Here’s an example. It dumps the raw data structure of a CPython integer. from ctypes import string_at from sys import getsizeof a = 0x7fff print(string_at(id(a),getsizeof(a)).hex()) Output: 0200000000000000d00fbeaafe7f00000100000000000000ff7f0000 Note that this works with the CPython implementation because id() happens to return the virtual memory address of a Python object, but this … Read more

Address of an array

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 … Read more

How can a non-assigned string in Python have an address in memory?

Python reuses string literals fairly aggressively. The rules by which it does so are implementation-dependent, but CPython uses two that I’m aware of: Strings that contain only characters valid in Python identifiers are interned, which means they are stored in a big table and reused wherever they occur. So, no matter where you use “cat”, … Read more

How to access physical addresses from user space in Linux?

busybox devmem busybox devmem is a tiny CLI utility that mmaps /dev/mem. You can get it in Ubuntu with: sudo apt-get install busybox Usage: read 4 bytes from the physical address 0x12345678: sudo busybox devmem 0x12345678 Write 0x9abcdef0 to that address: sudo busybox devmem 0x12345678 w 0x9abcdef0 Source: https://github.com/mirror/busybox/blob/1_27_2/miscutils/devmem.c#L85 mmap MAP_SHARED When mmapping /dev/mem, you … Read more