1

Static writable data is not supported. I could store it in the heap itself, only if there is some way to store a flag indicating if initialization is called.

Has this ever been done before?

This is the failed code: https://github.com/oxfeeefeee/smalloc/blob/3ccb02ee416fa64943b06df7ebb3aa4684cada77/src/lib.rs

1 Answer 1

2

I took a closer look at the example https://github.com/solana-labs/solana-program-library/blob/master/examples/rust/custom-heap/src/entrypoint.rs, and there is a way to tell if "alloc" is called for the first time:

let mut pos = *POS_PTR;
        if pos == 0 {
            // First time, set starting position
            pos = TOP_ADDRESS;
        }

update: The code may need more polishing but passes basic tests: https://github.com/oxfeeefeee/smalloc

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.