mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
commit
26140158ab
@ -29,6 +29,7 @@ void *fb_alloc(uint32_t size)
|
|||||||
if (!size) {
|
if (!size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size=((size+sizeof(uint32_t)-1)/sizeof(uint32_t))*sizeof(uint32_t);// Round Up
|
size=((size+sizeof(uint32_t)-1)/sizeof(uint32_t))*sizeof(uint32_t);// Round Up
|
||||||
char *result = pointer - size;
|
char *result = pointer - size;
|
||||||
char *new_pointer = result - sizeof(uint32_t);
|
char *new_pointer = result - sizeof(uint32_t);
|
||||||
@ -43,11 +44,37 @@ void *fb_alloc(uint32_t size)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns null pointer without error if size==0
|
// returns null pointer without error if passed size==0
|
||||||
void *fb_alloc0(uint32_t size)
|
void *fb_alloc0(uint32_t size)
|
||||||
{
|
{
|
||||||
void *mem = fb_alloc(size);
|
void *mem = fb_alloc(size);
|
||||||
memset(mem, 0, size);
|
memset(mem, 0, size); // does nothing if size is zero.
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *fb_alloc_all(uint32_t *size)
|
||||||
|
{
|
||||||
|
int temp = pointer - ((char *) FB_PIXELS()) - sizeof(uint32_t);
|
||||||
|
|
||||||
|
if (temp < sizeof(uint32_t)) {
|
||||||
|
*size = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*size = (temp / sizeof(uint32_t)) * sizeof(uint32_t); // Round Down
|
||||||
|
char *result = pointer - *size;
|
||||||
|
char *new_pointer = result - sizeof(uint32_t);
|
||||||
|
|
||||||
|
*((uint32_t *) new_pointer) = *size + sizeof(uint32_t); // Save size.
|
||||||
|
pointer = new_pointer;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns null pointer without error if returned size==0
|
||||||
|
void *fb_alloc0_all(uint32_t *size)
|
||||||
|
{
|
||||||
|
void *mem = fb_alloc_all(size);
|
||||||
|
memset(mem, 0, *size); // does nothing if size is zero.
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
void fb_alloc_init0();
|
void fb_alloc_init0();
|
||||||
void *fb_alloc(uint32_t size);
|
void *fb_alloc(uint32_t size);
|
||||||
void *fb_alloc0(uint32_t size);
|
void *fb_alloc0(uint32_t size);
|
||||||
|
void *fb_alloc_all(uint32_t *size); // returns pointer and sets size
|
||||||
|
void *fb_alloc0_all(uint32_t *size); // returns pointer and sets size
|
||||||
void fb_free();
|
void fb_free();
|
||||||
void fb_free_all();
|
void fb_free_all();
|
||||||
#endif /* __FF_ALLOC_H__ */
|
#endif /* __FF_ALLOC_H__ */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user