mirror of
https://github.com/vivier/EMILE.git
synced 2026-04-21 01:16:32 +00:00
Add malloc_top() that try to allocate memory at top of memory
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user