I would like to allocate memory in Linux in the process at a specific address. In fact, I would like to do something like: I will have a number of processes. Each process will call the initialization function in the library (written by me), which will allocate some memory in the address space of the process (which will store information related to the process). This will be done by every process.
Once this memory is allocated, the last program will call another function in the library. Now this function would like to access the allocated memory (containing information about the process) by the first function.
The problem is that I canβt save the address of the memory allocated in the address space of the process in the library (not even in the static pointer, because there are a number of processes), and I donβt even want the user program to save this address. I just donβt want the user program to know that the library allocated by the library is allocated in their address space. The library function will be an abstraction for them, and they should just use them.
Is it possible to overcome this problem. I thought that whenever a process calls a library initialization function that allocates memory, memory is always allocated to the same address (say, 10000) throughout the process, regardless of all the others.
Thus, any library function that wants to access this memory can easily execute: char *p=10000;
and then access, which will have access to the address space of a process called a library function.
source share