What affects the size of the value of a memory address?
I look at the memory address of the rust process and it has a very large value(e.g. 3092365760128). But this is not a problem, the rust process reads and writes these memory addresses normally.
But when the rust calls some scripting tool DLLs, the scripts crash frequently with the message "Critical Error: Invalid memory read/write.", which seems to be because the rust process' memory address is too large. If the DLL is used in other software, it usually has a small memory address (e.g. 10561576)
10561576 is really a huge difference compared to 3092365760128.
What causes this difference? Is there a way to make it smaller?
The loader and the OS.
The address you see is a virtual address and has nothing to do with the actual physical address. The loader decides how to map various parts of the process into memory, while the OS decides which virtual addresses are assigned to your process. (on WIndows, the details may differ but the idea is essentially this).
It's usually not so simple. For starters, if the DLL and your Rust process are independent processes, then they have separate virtual address spaces, unless you specifically set up shared pages. So, a blind read from the DLL will cause a crash since one process is not usually allowed to read the address space of another process.
Have you read the code of the other software? Maybe they are written to invoke the DLL with shared pages?
That's about all I can say without further context.
Thanks.
You can understand it as python.dll, which runs its own PY code, but it belongs to the rust process.
I didn't read the address of the DLL through rust, I printed the memory address of itself using python code.
Same code:
Load python.dll with python.exe, the memory address of one of its variables is usually "10561576 "
Loading python.dll with rust.exe, which usually has a variable with a memory address of "3092365760128"
I should emphasize that rust just loads a python.dll thread and does not interact with it in any way, let alone read or write memory addresses.
The "memory read/write error" is an internal error in the python thread.
Yes, it is during loading when the addresses of many variables in your DLL is decided.
So, how are you loading the DLL in Rust? What code are you using?
I am not surprised, but I am curious.
A normal 64-bit process might have a variable address of "10111448".
A 64-bit rust process, on the other hand, has a variable with a memory address of "2706522757248".
...when executed on Online C Compiler - online editor, prints e.g. 0x55988860c2a0, which is 94113611432608 - even larger then what you've got yourself. But that shouldn't matter anyway: either you do the correct thing, and OS manages the memory in such a way that you can call what you expect; or you do the incorrect thing, and even the adjacent memory region is treated as inaccessible.
Yes, the size of this value does not matter to rust, it is safe enough. The problem now is that the DLL called by rust inherits the same address, and it cannot read or write to such a huge address.
This memory address is more like a real physical address. For example,
in this example I get : 94337159334608 -> 85.7 TB
Think of it another way too - why is rust's memory address larger than other 64-bit memory addresses? I can't tell if the DLL is wrong or not. Because only rust can't use it properly.
===
You can interpret it as a kind of mischievous banter.
This is because if the hard disk is used as virtual memory, its size can be interpreted exactly as the size of the hard disk.