-
-
Save MasterDuke17/e66c3273efdde888d51a4b4647801f49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Reallocs a piece of memory to the specified size, using the FSA. */ | |
void * MVM_fixed_size_realloc_at_safepoint(MVMThreadContext *tc, MVMFixedSizeAlloc *al, void * p, size_t old_bytes, size_t new_bytes) { | |
#if FSA_SIZE_DEBUG | |
MVMFixedSizeAllocDebug *dbg = MVM_fixed_size_alloc(tc, al, new_bytes); | |
memcpy(dbg->memory, p + sizeof(MVMuint64), new_bytes > old_bytes ? old_bytes : new_bytes); | |
MVM_fixed_size_free_at_safepoint(tc, al, old_bytes, p); | |
dbg->alloc_size = new_bytes; | |
return &(dbg->memory); | |
#else | |
MVMuint32 old_bin = bin_for(old_bytes); | |
MVMuint32 new_bin = bin_for(new_bytes); | |
if (old_bin == new_bin) { | |
return p; | |
} | |
else { | |
void *allocd = MVM_fixed_size_alloc(tc, al, new_bytes); | |
memcpy(allocd, p, new_bin > old_bin ? old_bytes : new_bytes); | |
MVM_fixed_size_free_at_safepoint(tc, al, old_bytes, p); | |
return allocd; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment