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;
}