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

内存池局部变量改为全局变量 #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions MyTinySTL/alloc.h
Original file line number Diff line number Diff line change
@@ -100,7 +100,9 @@ inline void* alloc::allocate(size_t n)
void* r = M_refill(M_round_up(n));
return r;
}
my_free_list = result->next;
// 局部变量不会反映到全局
// my_free_list = result->next;
free_list[M_freelist_index(n)] = result->next;
return result;
}

@@ -116,7 +118,9 @@ inline void alloc::deallocate(void* p, size_t n)
FreeList* my_free_list;
my_free_list = free_list[M_freelist_index(n)];
q->next = my_free_list;
my_free_list = q;
// 局部变量不会反映到全局
// my_free_list = q;
free_list[M_freelist_index(n)] = q;
}

// 重新分配空间,接受三个参数,参数一为指向新空间的指针,参数二为原来空间的大小,参数三为申请空间的大小