mirror of
https://github.com/CPunch/Cosmo.git
synced 2025-10-15 05:30:09 +00:00
do GC before table array is allocated
This commit is contained in:
15
src/cmem.c
15
src/cmem.c
@@ -27,10 +27,7 @@ void *cosmoM_reallocate(CState* state, void *buf, size_t oldSize, size_t newSize
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
// if the state isn't frozen && we've reached the GC event
|
||||
if (!(cosmoM_isFrozen(state)) && state->allocatedBytes > state->nextGC) {
|
||||
cosmoM_collectGarbage(state); // cya lol
|
||||
}
|
||||
cosmoM_checkGarbage(state, 0);
|
||||
#endif
|
||||
|
||||
// otherwise just use realloc to do all the heavy lifting
|
||||
@@ -44,6 +41,16 @@ void *cosmoM_reallocate(CState* state, void *buf, size_t oldSize, size_t newSize
|
||||
return newBuf;
|
||||
}
|
||||
|
||||
COSMO_API bool cosmoM_checkGarbage(CState *state, size_t needed) {
|
||||
if (!(cosmoM_isFrozen(state)) && state->allocatedBytes + needed > state->nextGC) {
|
||||
cosmoM_collectGarbage(state); // cya lol
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void markObject(CState *state, CObj *obj);
|
||||
void markValue(CState *state, CValue val);
|
||||
|
||||
|
Reference in New Issue
Block a user