pooled memo allocation

19 views
Skip to first unread message

tx...@sina.com

unread,
Jul 1, 2016, 12:51:37 AM7/1/16
to Netty discussions
hey,

i have read the source code about the memo allocation, and i found a problem which is when we allocate the sub-page ,if the element size of the page does not equal  the normalized 
size , it will return -1(the part  i have already marked as read as below ) ,which means the allocation is failed , the thing i am wandering is that why it is marked as failed directly ,why not search for another parent node,then do the
allocation.

 private long allocateSubpage(int normCapacity, int curIdx, int val) {
        int state = val & 3;
        if (state == ST_BRANCH) {
            int nextIdx = curIdx << 1 ^ nextRandom();
            long res = branchSubpage(normCapacity, nextIdx);
            if (res > 0) {
                return res;
            }

            return branchSubpage(normCapacity, nextIdx ^ 1);
        }

        if (state == ST_UNUSED) {
            return allocateSubpageSimple(normCapacity, curIdx, val);
        }

        if (state == ST_ALLOCATED_SUBPAGE) {
            PoolSubpage<T> subpage = subpages[subpageIdx(curIdx)];
            int elemSize = subpage.elemSize;
            if (normCapacity != elemSize) {
                return -1;
            }

            return subpage.allocate();
        }

        return -1;
    }

이희승 (Trustin Lee)

unread,
Jul 4, 2016, 3:46:44 AM7/4/16
to ne...@googlegroups.com
Hi,
 
It's because a subpage is always allocated at the leaf level? It's a recursive search, so returning -1 there will make the caller try other node whose state is ST_ALLOCATED_SUBPAGE.
 
HTH,
T
 
--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
 
Reply all
Reply to author
Forward
0 new messages