Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get free heap size? #30

Open
MoonLight423 opened this issue Oct 24, 2023 · 3 comments
Open

How can I get free heap size? #30

MoonLight423 opened this issue Oct 24, 2023 · 3 comments

Comments

@MoonLight423
Copy link

First,it,s celebratory that tlsf work well in SDRAM with STM32H750.

But how can I know the free size just like esp_get_free_heap_size();
I try to log info after malloc, but the value not change.Or I need to count that in my way?
log_d("tlsf size:%d", tlsf_size()); log_d("tlsf align size:%d", tlsf_align_size()); log_d("tlsf block size_min:%d", tlsf_block_size_min()); log_d("tlsf block size max:%d", tlsf_block_size_max());

@paniq
Copy link

paniq commented Feb 20, 2024

@MoonLight423 as documented in the header, these functions all return constants. There is no function that gives you the available memory directly. However, you can use tlsf_walk_pool to get all unused blocks, and tlsf_block_size to get the size of each unused block.

@copilotenstar
Copy link

copilotenstar commented Nov 21, 2024

tlsf_walk_pool doesn't seem to work? block_is_last always returns true and never calls the walker callback.

int pool_size = 20 * 1024 * 1024;
    void* pool = malloc(pool_size);
    void* tlsf = tlsf_create_with_pool(pool, pool_size);

    tlsf_malloc(tlsf, 24);
    tlsf_malloc(tlsf, 32);
    tlsf_malloc(tlsf, 64);

    // ........

    void
    block_info(void* ptr, size_t size, int used, void* user)
    {
        if (used) {
            printf("Block: %p, Size: %zu\n", ptr, size);
        }
    }

    tlsf_walk_pool(pool, block_info, NULL);

@copilotenstar
Copy link

seems like you need to use tlsf_get_pool. For anyone else that comes across this.

correct should be:

void* pool = malloc(pool_size);
void* tlsf = tlsf_create_with_pool(pool, pool_size);
// .....
 tlsf_walk_pool(tlsf_get_pool(tlsf), block_info, NULL);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants