Tue, 22 Feb 2000 Edgar F. Hilton wrote:
> Folks,
>
> What is the best way to dynamically allocate memory for FLOATS in real time
> linux modules (not within init_module)? There is a section of code which is
> not time critical and which does not run in unison with any time critical
> tasks. Consequently, it is in this piece of code that I would like to do some
> dynamic memory allocations. Stated differently, I am hoping to find anything
> that rhymes with malloc, realloc, and calloc. Would kmalloc be my only
> friend?
Why are you running non-realtime stuff in the module in the first place?
Generally, all non or soft RT code belongs in user space, where you have all
the luxuires; protected memory, standard libraries, simple file I/O and so on...
Anyway, if you really want to stay in kernel space, you could always consider
building your own memory management. If you need only objects of the same size,
using a pool (LIFO stack) of objects is a very simple and efficient aproach.
Besides, the LIFO (last in, first out) gives you cache optimization for free,
in case you need to worry about performance.
---8<-------------------------------------------
struct object_t {
struct object_t *next;
float data;
};
struct object_t *pool_top;
struct object_t *object_alloc(void)
{
struct object_t *obj = pool_top;
if(pool_top) {
pool_top = obj->next;
return obj;
} else
return 0; /* Out of objects! */
}
void object_free(struct object_t *obj_alloc)
{
obj->next = pool_top;
pool_top = obj;
}
------------------------------------------->8---
Init pool by allocating enough objects and feeding them to object_free().
Regards,
//David
P r o f e s s i o n a l L i n u x A u d i o
· ··-------------------------------------------------·· ·
MuCoS - http://www.linuxdj.com/mucos
Audiality - http://www.angelfire.com/or/audiality
David Olofson - [EMAIL PROTECTED]
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/