memory-address

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

假装没事ソ 提交于 2019-12-20 09:10:20
问题 Can someone explain this to me? So I've been playing with the id() command in python and came across this: >>> id('cat') 5181152 >>> a = 'cat' >>> b = 'cat' >>> id(a) 5181152 >>> id(b) 5181152 This makes some sense to me except for one part: The string 'cat' has an address in memory before I assign it to a variable. I probably just don't understand how memory addressing works but can someone explain this to me or at least tell me that I should read up on memory addressing? So that is all well

Returning an address to a local variable vs returning a pointer to a local variable

守給你的承諾、 提交于 2019-12-20 04:32:39
问题 I have this in my testing.cpp: class Supp{ public: virtual Supp* add(Supp& val) = 0; }; class SubA : public Supp{ public: int val; SubA(int a){ val = a; } int getVal(){ return val; } Supp* add(Supp& value){ SubA& a = dynamic_cast<SubA&>(value); int tempVal = a.getVal(); int sum = val + tempVal; SubA b =SubA(sum); return &b; } }; and the lines SubA b = SubA(sum); return &b; gives and error because itreturns the address to a local variable which is very bad to do, so i changed it to SubA* b

pointer to an int array gives the same address as when it is dereferenced

梦想与她 提交于 2019-12-20 03:04:22
问题 I have the following code: #include <iostream> using namespace std; int main() { int g[] = {9,8}; int (*j)[2] = &g; cout << "*(j):" << *(j) << endl; cout << "j:" << j << endl; cout << "&j:" << &j << endl; cout << "&(*j)" << &(*j) << endl; cout << "*(*j):" << *(*j) << endl; return 0; } which ouputs: *(j):0x7fff5ab37c7c j:0x7fff5ab37c7c &j:0x7fff5ab37c70 &(*j)0x7fff5ab37c7c *(*j):9 I think that j is a pointer to an array of two integer. And &g is the address of the whole array. Then j store the

Standard way to find base address of struct from a member

五迷三道 提交于 2019-12-20 02:57:27
问题 struct Data { int a; std::string b; float c; }; std::string* allocateDataAndGetString() { Data* dataPtr(someAllocator.allocate<Data>()); return &dataPtr.b; } Data* getBaseDataPtrFromString(std::string* mStringMember) { // ??? } int main() { std::string* stringPtr(allocateDataAndGetString()); Data* dataPtr(getBaseDataPtrFromString } I have a Data instance allocated on the heap, and a pointer to its std::string b; member. How do I get the base address of the Data instance the string is a member

How is a physical address generated in 8086?

霸气de小男生 提交于 2019-12-19 03:53:11
问题 In the 8086 architecture, the memory space is 1 MiB in size and divided into logical segments of up to 64 KiB each. i.e. it has 20 address lines thus the following method is used: That the data segment register is shifted left 4 bits then added to the offset register My question is: How we do the shift operation although all the registers are only 16 bits 回答1: Address translation is done internally by a special unit without using the registers available to user code to store intermediate

How to manually symbolicate a crash log with atos

一个人想着一个人 提交于 2019-12-18 13:38:44
问题 After searching all over the internet to find a way to symbolicate my crash logs I received from Apple, I finally figured out how to use the atos command in terminal to symbolicate the crash logs. I have the dSYM file, the .app file and the crash logs in the same folder, and using atos -arch armv7 -o APPNAME I have been able to enter memory addresses, and sometimes (but quite rarely) a method name has come up. To be perfectly honest, I don't have much experience with terminal, or crash logs.

What memory address spaces are there?

妖精的绣舞 提交于 2019-12-18 11:45:56
问题 What forms of memory address spaces have been used? Today, a large flat virtual address space is common. Historically, more complicated address spaces have been used, such as a pair of a base address and an offset, a pair of a segment number and an offset, a word address plus some index for a byte or other sub-object, and so on. From time to time, various answers and comments assert that C/C++ pointers are essentially integers. That is an incorrect model for C/C++, since the variety of

One memory location in a computer stores how much data?

喜你入骨 提交于 2019-12-18 11:06:53
问题 Assume 32 Bit OS. One memory location in a computer stores how much data? Whats the basic unit of memory storage in a computer? For Example to a store a integer what will be the memory addresses required? If basic unit is BYTE the integer requires 4 bytes. So if I need to store a byte then if start putting in the 1st byte in memory location 0001 then will my integer end at 0003 memory location? Please correct me if am wrong? 回答1: Most commonly, modern systems are what you call "byte

C method for iterating through a struct's members like an array?

﹥>﹥吖頭↗ 提交于 2019-12-18 04:17:28
问题 Let's say I have a vector class: typedef struct vec3_s { float x, y, z; } vec3; But, I would like to be able to iterate through it without converting it to an array of floats. While a cast is acceptable in this case, I'm curious to see if anything along the lines of C++ like functionality is doable in straight C. For example, in C++, since std::vector< T > has the subscript [] operator overloaded, I can pass the address of its first index to a function taking a void* . i.e., void do_something

What exactly is the purpose of the (asterisk) in pointers?

自古美人都是妖i 提交于 2019-12-17 18:46:25
问题 I'm new to programming and I'm trying to wrap my head around the idea of 'pointers'. int main() { int x = 5; int *pointerToInteger = & x; cout<<pointerToInteger; } Why is it that when I cout << pointerToInteger; the output is a hexdecimal value, BUT when I use cout << *pointerToInteger; the output is 5 ( x=5). 回答1: * has different meaning depending on the context. Declaration of a pointer int* ap; // It defines ap to be a pointer to an int. void foo(int* p); // Declares function foo. // foo