Skip to content

Commit

Permalink
gamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsella committed Sep 17, 2023
1 parent c753e9e commit b7efb40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ t_alloc *new_alloc(t_mmap *mmap, void *ptr, size_t size) {
}

t_alloc *find_alloc(size_t size) {
size += ALIGNMENT; // add space to align the return ptr
if (!g_mmap)
return NULL;
for (t_mmap *mmap = g_mmap; mmap; mmap = mmap->next) {
if (mmap->type != get_mmap_type(size - ALIGNMENT))
if (mmap->type != get_mmap_type(size))
continue;

// in case it's the first allocation of a mmap
if (!mmap->alloc)
return new_alloc(mmap, alignp(MMAP_SHIFT(mmap)), size);
/* return new_alloc(mmap, MMAP_SHIFT(mmap), size); */

t_alloc *alloc = mmap->alloc;
void *ptr = alignp(MMAP_SHIFT(mmap));
while (alloc) { // seach for space between allocated spaces
size_t space = (void *)alloc - ptr;
if (ptr < (void *)alloc && space >= (size_t)ALLOC_SHIFT(size))
// size + ALIGNMENT because we need to have space to align the alloc
if (ptr < (void *)alloc && space >= (size_t)ALLOC_SHIFT(size + ALIGNMENT))
return new_alloc(mmap, ptr, size);

ptr = alignp(ALLOC_SHIFT(alloc) + alloc->size);
alloc = alloc->next;
}
// allocated space after the last allocated space
if ((void *)(MMAP_SHIFT(mmap) + mmap->size - ptr) >= ALLOC_SHIFT(size))
if ((void *)(MMAP_SHIFT(mmap) + mmap->size - ptr) >=
ALLOC_SHIFT(size + ALIGNMENT))
return new_alloc(mmap, ptr, size);
}
return NULL;
Expand Down
9 changes: 0 additions & 9 deletions test1.c

This file was deleted.

0 comments on commit b7efb40

Please sign in to comment.