Add malloc_top() that try to allocate memory at top of memory

This commit is contained in:
Laurent Vivier 2005-09-05 21:10:31 +00:00
parent 1c814a938b
commit 4757dff52c
2 changed files with 23 additions and 0 deletions

View File

@ -304,6 +304,28 @@ void *malloc_contiguous(size_t size)
return contiguous;
}
void *malloc_top(size_t size)
{
void *top;
void* tmp;
long bubble;
bubble = bank_mem_avail() - size;
do {
tmp = malloc_contiguous(bubble);
if (tmp)
{
top = malloc(size);
free(tmp);
if (top)
return top;
}
bubble -= 1024 * 1024; /* decrease of 1 MB */
} while (bubble > 0);
return NULL;
}
#ifdef BANK_DUMP
void bank_dump()
{

View File

@ -31,3 +31,4 @@ extern int logical2physical(unsigned long logical, unsigned long *physical);
extern int physical2logical(unsigned long physical, unsigned long *logical);
extern int check_full_in_bank(unsigned long start, unsigned long size);
extern void *malloc_contiguous(size_t size);
extern void *malloc_top(size_t size);