gpt4 book ai didi

rust - 如何避免我的 anchor 程序抛出 "Access violation in stack frame"?

转载 作者:行者123 更新时间:2023-12-05 09:02:51 26 4
gpt4 key购买 nike

我的 Anchor 程序有一个如下所示的指令结构:

#[derive(Accounts)]
pub struct MyInstruction<'info> {
pub my_account: Account<'info, MyAccount>,

// ...
}

#[account]
pub struct MyAccount {
// ... Many different fields
}

当我尝试运行使用该结构的指令时,我得到了一个奇怪的堆栈错误,如下所示:

Program failed to complete: Access violation in stack frame 3 at address 0x200003fe0 of size 8 by instruction #28386

什么给了?

最佳答案

默认情况下,Anchor 会将您的帐户放在堆栈中。但是,很可能是因为您的帐户很大,或者您有很多帐户,所以堆栈空间不足。

如果您查看上面的日志,您可能会遇到如下所示的错误:

Stack offset of -4128 exceeded max offset of -4096 by 32 bytes, please minimize large stack variables

要解决这个问题,您可以尝试Box您的帐户结构,将它们移动到堆中:

#[derive(Accounts)]
pub struct MyInstruction<'info> {
// Note the Box<>!
pub my_account: Box<Account<'info, MyAccount>>,
}

关于rust - 如何避免我的 anchor 程序抛出 "Access violation in stack frame"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70747729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com