gc测试
This commit is contained in:
@@ -14,6 +14,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/source-charset:utf-8)
|
||||
add_compile_options(/execution-charset:utf-8)
|
||||
endif ()
|
||||
add_compile_options(/Zc:preprocessor)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -30,10 +30,10 @@ class Garbage final : public IGarbage {
|
||||
|
||||
public:
|
||||
explicit Garbage(T* ptr) : IGarbage(ptr) {}
|
||||
void collect() override { delete static_cast<T*>(ptr); }
|
||||
void collect() override { delete static_cast<T*>(deallocating(ptr)); }
|
||||
|
||||
protected:
|
||||
void deleteThis() override { delete this; }
|
||||
void deleteThis() override { delete deallocating(this); }
|
||||
};
|
||||
|
||||
class GarbageCollector {
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
/** 只能在gameThread调用 */
|
||||
template <TypeName T>
|
||||
void submit(T* ptr) noexcept(false) {
|
||||
IGarbage* garbage = new Garbage<T>(ptr);
|
||||
IGarbage* garbage = allocatedFor(new Garbage<T>(ptr));
|
||||
if (IGarbage* end = submittedEnd) { // 后续添加,可能存在线程竞争
|
||||
while (end->next) end = end->next; // 理论上不会进入循环,但防止万一
|
||||
end->next = garbage;
|
||||
|
||||
@@ -170,7 +170,7 @@ bool AnywhereIterator<T, L>::operator==(const AnywhereIteratorEnd& other) const
|
||||
|
||||
template <typename T, typename L>
|
||||
int AnywhereEditableList<T, L>::pushCopy(T* value) noexcept {
|
||||
T* nv = new T(*value);
|
||||
T* nv = allocatedFor(new T(*value));
|
||||
return pushNewed(nv);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ int AnywhereEditableList<T, L>::pushThis(T* value) noexcept {
|
||||
template <typename T, typename L>
|
||||
int AnywhereEditableList<T, L>::pushNewed(T* value) noexcept {
|
||||
const int ret = pushThis(value);
|
||||
if (ret) delete value;
|
||||
if (ret) delete deallocating(value);
|
||||
else value->managedByList = true;
|
||||
return ret;
|
||||
}
|
||||
@@ -205,6 +205,6 @@ int AnywhereEditableList<T, L>::pop(T* value) noexcept {
|
||||
value->list = nullptr;
|
||||
value->next->prev = value->prev;
|
||||
value->prev->next = value->next;
|
||||
if (value->managedByList) delete value;
|
||||
if (value->managedByList) delete deallocating(value);
|
||||
Success();
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user