I made a function by which I can create memory pools but how can I select them after creating them?
boolean create_memory_pool(char *name, int size)
{
boolean result;
result = false;
name = malloc(size));
if( name != NULL)
result = true;
return result;
}
In main function if I created more than one 1 memory pools for example
int main()
{
boolean x;
x = create_memory_pool( "pool1", 1024);
x = create_memory_pool( "pool2", 2048);
x = create_memory_pool( "pool3", 2048);
// now how to select pool1 or pool2 or pool3
}
what I am trying to do is create a function called select by which I can pass the name of pool and it returns some reference to the pool called.
boolean select( char *name)
{
//return true if pool of name "name" is selected.
}
I think I need to declare a global variable X which acts as a reference to currently selected pool which is NULL in the beginning. And on creating each memory pool I can pass the function "select(name)" in the end of "create memory pool" function so on creation of new memory pool it will be automatically selected to the global X. or I can pass the name of any pool which I want to select. but I am stuck in thinking about its implementation.
char *variable. In fact that value just gets ignored. If you want to store the pointers linked to a name, you will have to work the data structure yourself. Why do you think that such thing is possible directly as part of the C language is beyond me.