Static Pointers / kmalloc
Posted: Wed Mar 24, 2004 12:40 am
if kmalloc is void *kmalloc(int bytes) then how is it possible to get a function to reuse memore allocated to it. On instinct (and I think logic) I would say something like this:
static int *thing = kmalloc(sizeof(int));
It seems pretty simple. But GCC doesn't like it because kmalloc() isn't a constant and it's going to try to handle the pointer at linktime before kmalloc() is ready. So I understand why that detonates, but how else can I get a pointer that will point to the same memory through multiple calls?
The only method I can think of that would avoid this is to save the addresses in non-pointer statics and assign the pointers to those statics but that's really inefficient considering you have a full integer (size of address) overhead for every single variable you allocate memory for (bleh).
static int *thing = kmalloc(sizeof(int));
It seems pretty simple. But GCC doesn't like it because kmalloc() isn't a constant and it's going to try to handle the pointer at linktime before kmalloc() is ready. So I understand why that detonates, but how else can I get a pointer that will point to the same memory through multiple calls?
The only method I can think of that would avoid this is to save the addresses in non-pointer statics and assign the pointers to those statics but that's really inefficient considering you have a full integer (size of address) overhead for every single variable you allocate memory for (bleh).