krakjoe / apcu

APCu - APC User Cache
Other
957 stars 193 forks source link

Idea: Avoid fragmentation/cache clears internally #479

Open TysonAndre opened 1 year ago

TysonAndre commented 1 year ago

Related to https://github.com/krakjoe/apcu/issues/369

Making a note on approaches I'd thought of for avoiding fragmentation to refer to later

    if (cur->size == realsize || (cur->size > realsize && cur->size < (realsize + (MINBLOCKSIZE + fragment)))) {
        /* cur is big enough for realsize, but too small to split - unlink it */
        *(allocated) = cur->size - block_size;
        prv = BLOCKAT(cur->fprev);
        prv->fnext = cur->fnext;
        BLOCKAT(cur->fnext)->fprev = OFFSET(prv);
        NEXT_SBLOCK(cur)->prev_size = 0;  /* block is alloc'd */

Userland workarounds: