Skip to content

Commit

Permalink
Expand heap when trying consecutive gc (jsk-ros-pkg/jsk_roseus#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
Affonso-Gui committed Nov 10, 2022
1 parent 218150b commit 5190f66
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lisp/c/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ struct chunk *chunklist=NULL;
long gccount,marktime,sweeptime;
long alloccount[MAXBUDDY];

/* counter to control new memory allocation when performance is low */
/* see https://github.com/jsk-ros-pkg/jsk_roseus/issues/728 */
long gc_consecutive_count;
#define GC_CONSECUTIVE_COUNT_LIMIT 2

/*disposal processing*/
#define MAXDISPOSE 256
static pointer dispose[MAXDISPOSE];
Expand Down Expand Up @@ -167,6 +172,7 @@ register int k;
j=newchunk(k);
if (j==ERR) return(j);
}
gc_consecutive_count=0;
return(j);
}

Expand Down Expand Up @@ -302,6 +308,12 @@ register int req; /*index to buddy: must be greater than 0*/
/* fprintf(stderr, "GC: free=%d total=%d, margin=%f\n",
freeheap, totalheap, fltval(speval(GCMARGIN))); */
gc(); collected=1;
if (gc_consecutive_count > GC_CONSECUTIVE_COUNT_LIMIT) {
if (fillchunk(DEFAULTCHUNKINDEX) == ERR) {
#if THREADED
mutex_unlock(&alloc_lock);
#endif
error(E_ALLOCATION);}}
goto alloc_again;}
j=fillchunk(DEFAULTCHUNKINDEX);
if (j==ERR) {
Expand Down Expand Up @@ -788,6 +800,7 @@ void gc()
{ if (debug) fprintf(stderr,"\n;; gc:");
// breakck;
gccount++;
gc_consecutive_count++;
markall();
sweepall();
if (debug) {
Expand All @@ -811,6 +824,7 @@ void gc()
}
// breakck;
gccount++;
gc_consecutive_count++;
times(&tbuf1);

#if THREADED
Expand Down

0 comments on commit 5190f66

Please sign in to comment.