Skip to content

Commit

Permalink
Merge pull request #4 from rajamukherji/dev
Browse files Browse the repository at this point in the history
Add ramp_clear to reuse memory blocks between iterations.
  • Loading branch information
rajamukherji authored Sep 28, 2018
2 parents 476502d + 6fec4a1 commit a0ff044
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ramp.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ void ramp_reset(ramp_t *Ramp) {
Ramp->Pages = 0;
}

void ramp_clear(ramp_t *Ramp) {
for (ramp_ext_t *Ext = Ramp->Exts; Ext; Ext = Ext->Next) free(Ext->Bytes);
size_t FreeSpace = Ramp->PageSize;
for (ramp_page_t *Page = Ramp->Pages; Page; Page = Page->Next) Page->FreeSpace = FreeSpace;
Ramp->Exts = 0;
}

void ramp_free(ramp_t *Ramp) {
ramp_reset(Ramp);
free(Ramp);
Expand Down
9 changes: 8 additions & 1 deletion src/ramp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ ramp_t *ramp_new(size_t PageSize);
void *ramp_alloc(ramp_t *Ramp, size_t Size);

/**
* \brief frees memory allocated within ramp_t instance.
* \brief frees memory allocated within ramp_t instance and frees memory blocks.
*
* \param Ramp ramp_t object allocated with ramp_new.
*/
void ramp_reset(ramp_t *Ramp);

/**
* \brief frees memory allocated within ramp_t instance while keeping memory blocks for reuse.
*
* \param Ramp ramp_t object allocated with ramp_new.
*/
void ramp_free(ramp_t *Ramp);

/**
* \brief frees a ramp_t object and all allocated pages.
*
Expand Down

0 comments on commit a0ff044

Please sign in to comment.