mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-22 10:29:31 +00:00
Add malloc_top() that try to allocate memory at top of memory
This commit is contained in:
parent
1c814a938b
commit
4757dff52c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user