3

What is the maximum memory that a solana program can allocate before throwing an out of memory exception, and how is it handled during the program's execution? Is this documented anywhere, like the compute-budget (Is there something like a memory-budget anywhere)? Also, is there a way to debug the program and see the memory usage?

1 Answer 1

2

The maximum amount of heap space you get in one instruction is 32KB. The current allocator is a naive bump allocator, which does not try to reuse memory, so sometimes you're better off reusing structures.

Also, you get 4096 bytes on each stack frame.

There aren't any syscalls to check heap usage, but you can define a custom heap which logs how much you've used, similar to this example: https://github.com/solana-labs/solana-program-library/blob/master/examples/rust/custom-heap/src/entrypoint.rs

More information at https://docs.solana.com/developing/on-chain-programs/overview#heap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.