formatted and combined logic #1

Merged
husky merged 3 commits from x02/scythe:develop into develop 2026-10-05 20:14:16 -07:00
Contributor

fixed the unsafe where the mutable borrow was occuring on the immutable reference to self :)

fixed the unsafe where the mutable borrow was occuring on the immutable reference to self :)
Owner

thank you a ton! very happy to have people helping to make my terribly hacked together code better :p

i'll test this in a bit and probably merge since everything looks good from what i can tell

thank you a ton! very happy to have people helping to make my terribly hacked together code better :p i'll test this in a bit and probably merge since everything looks good from what i can tell
Author
Contributor

you're welcome 🙏
I wasn't able to test it as i dont have the device that its built for however it did build without any warnings or errors

you're welcome 🙏 I wasn't able to test it as i dont have the device that its built for however it _did_ build without any warnings or errors
Owner

just tested it, it seems a bug was introduced in the memory allocator's block merging algorithm; because debugging in this environment is a nightmare, all i can tell you is that the number of buddy blocks before the allocations does not match the number of buddy blocks after the frees (which is what the following code i've included tests; output is "mem bad ):")

    let mut memalloc: MemAlloc<1024, 128> = MemAlloc::init(mem_start, mem_end);

    let len = memalloc.blocks.count_real();

    fb_draw_string(b"mem created...", 0, 0);

    let block1 = memalloc.alloc(11);
    if let Some(block1) = block1 {
        fb_draw_string(b"alloc blck 11", 0, 10);
        let block2 = memalloc.alloc(12);
        if let Some(block2) = block2 {
            fb_draw_string(b"alloc blck 12", 0, 20);
            memalloc.free(block1);
            fb_draw_string(b"free blok 11", 0, 30);
            memalloc.free(block2);
            fb_draw_string(b"free blck 12", 0, 40);

            if memalloc.blocks.count_real() == len {
                fb_draw_string(b"mem good!", 0, 50);
            } else {
                fb_draw_string(b"mem bad ):", 0, 50);
            }
        } else {
            fb_draw_string(b"fail blck 12", 0, 20);
        }
    } else {
        fb_draw_string(b"fail blck 11", 0, 10);
    }

    fb_update();

i can look further into this later if you'd like since you don't have access to hardware for testing, however i have some changes i'd like to push to develop first

since i hadn't until now considered that other people might wanna work on this, i'll start doing that stuff on a separate branch to keep develop cleaner for merges in the future

just tested it, it seems a bug was introduced in the memory allocator's block merging algorithm; because debugging in this environment is a nightmare, all i can tell you is that the number of buddy blocks before the allocations does not match the number of buddy blocks after the frees (which is what the following code i've included tests; output is "mem bad ):") ``` let mut memalloc: MemAlloc<1024, 128> = MemAlloc::init(mem_start, mem_end); let len = memalloc.blocks.count_real(); fb_draw_string(b"mem created...", 0, 0); let block1 = memalloc.alloc(11); if let Some(block1) = block1 { fb_draw_string(b"alloc blck 11", 0, 10); let block2 = memalloc.alloc(12); if let Some(block2) = block2 { fb_draw_string(b"alloc blck 12", 0, 20); memalloc.free(block1); fb_draw_string(b"free blok 11", 0, 30); memalloc.free(block2); fb_draw_string(b"free blck 12", 0, 40); if memalloc.blocks.count_real() == len { fb_draw_string(b"mem good!", 0, 50); } else { fb_draw_string(b"mem bad ):", 0, 50); } } else { fb_draw_string(b"fail blck 12", 0, 20); } } else { fb_draw_string(b"fail blck 11", 0, 10); } fb_update(); ``` i can look further into this later if you'd like since you don't have access to hardware for testing, however i have some changes i'd like to push to develop first since i hadn't until now considered that other people might wanna work on this, i'll start doing that stuff on a separate branch to keep develop cleaner for merges in the future
First-time contributor

oh hell yea

oh hell yea
Author
Contributor

alright thats cool I’ll have a look myself tonight and push any interesting changes if you can test it for me 😇

alright thats cool I’ll have a look myself tonight and push any interesting changes if you can test it for me 😇
Author
Contributor

im not too familiar with this paging (i've only really seen XOR allocators) is there any reason its different?

im not _too_ familiar with this paging (i've only really seen XOR allocators) is there any reason its different?
Author
Contributor

that latest commit should be the fix if you could test that pls and ty

that latest commit should be the fix if you could test that pls and ty
x02 changed title from formatted and combined logic to WIP: formatted and combined logic 2026-10-05 11:40:26 -07:00
x02 changed title from WIP: formatted and combined logic to formatted and combined logic 2026-10-05 11:40:35 -07:00
Owner

this is pretty much just as much of a direct port of the buddy block allocator pseudocode from wikipedia as i could do, i chose this because i wanted something with speed / flexibility in between a standard free list and like a user runtime allocator

i'll test the code now!

this is pretty much just as much of a direct port of the buddy block allocator pseudocode from wikipedia as i could do, i chose this because i wanted something with speed / flexibility in between a standard free list and like a user runtime allocator i'll test the code now!
Owner

seems to work fine! before i merge this, since this is the first outside contribution and i haven't yet published this, i'm going to license this repo under AGPL, do you have any issues with this?

seems to work fine! before i merge this, since this is the first outside contribution and i haven't yet published this, i'm going to license this repo under AGPL, do you have any issues with this?
Author
Contributor

I have no issues with that

I have no issues with that
husky merged commit dd5864063e into develop 2026-10-05 20:14:16 -07:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
husky/scythe!1
No description provided.