我如何 dedicate/allocate 自定义内存位置以便我可以在 C++ 中编辑该位置

How do I dedicate/allocate a custom memory location so that I can edit that location in c++

所以我正在尝试编辑内存中包含一堆数据的位置(使用我放入该位置的数据创建一个线程)。但是为了让程序运行,需要放在那个特定的位置。

for (int i = 0; i < dumpSize; i++) *(char*)(0x91F40000 + i) = dumpData[i];

如您所见,0x91F40000 是我想要数据所在的位置,但由于内存位置不可写,因此它实际上并没有更改该位置的内存。 我要怎么做才能编辑这个区域?

您可能想要使用 placement new operator (see also this)。重要的是 dumpData.

的类型

但是,您需要确保地址(在 0x91F40000 之后)是您 virtual address space. How to be sure of that is probably operating system specific. Because of ASLR 的一部分,该地址可能会有所不同。

我强烈怀疑您的代码有误。通常,sizeof(int) 是 4(字节)。那你要

for (int i = 0; i < dumpSize; i++)
   *(int*)(0x91F40000 + sizeof(int)*i) = dumpData[i];

我们不知道 dumpData 的类型是什么。或者你可以编码

for (int i = 0; i < dumpSize; i++)
   ((int*)0x91F40000)[i] = dumpData[i];

如果您的问题是关于不可写的虚拟内存位置,您可以使用特定的操作来更改它 system calls changing the virtual address space (or protection); on Linux or POSIX that would be mmap(2) & mprotect(2)

PS。您确定对地址 space、操作系统等了解足够吗?你的问题看起来很可疑或者 XY problem

在 XBOX 计算机上(你在评论中提到了这一点,但它应该进入问题),你需要了解 更多 关于 Xbox One system software or XBOX 360 system software. I have no idea about the details. Perhaps consider installing some Free60

你应该阅读Operating Systems : Three Easy Pieces至少能够更好地提出这样的问题。