【发布时间】:2015-08-08 18:03:14
【问题描述】:
我收到“访问冲突读取位置 0x0000000000000008”。使用此代码:
main.xcpp
Penguin::Game game;
game.memory = {};
game.memory.permanentSize = 1024*64;
game.memory.permanent = VirtualAlloc(0, game.memory.permanentSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
game.Start();
game.Start()
input = (Input *)memory.permanent;
*input = {}; // << Access violation reading location.
游戏结构
struct Game
{
struct Memory
{
uint64 permanentSize;
void *permanent;
};
Memory memory;
Input *input;
void Start();
};
但是。如果我尝试:
int *i = (int *)memory.permanent;
*i = 10;
有效。
我做错了什么?
【问题讨论】:
-
你有一个调试器,学习如何使用它!
标签: c++ pointers memory struct access-violation