Shared Memory is needed to share data between code running on application level and code running on kernel level. Because of virtual address spaces for each application and protected memory in kernel mode it is necessary to store data in memory where each level has access to.
- To allocate Shared Memory call KS_createSharedMem:
ksError = KS_createSharedMem( ppAppPtr, // Pointer to address for access from application level ppSysPtr, // Pointer to address for access from kernel level name, // Name to identify memory size, // size in bytes flags); // not used
- Now you have two pointers for the same area of memory, one for access from application level and one for access from kernel level
- Pay attention to use the correct pointer e.g. a callback function on kernel level needs ppSysPtr
- When Shared Memory is no longer needed free system resources by calling KS_freeSharedMem passing the application adress pointer
ksError = KS_freeSharedMem(pAppPtr);
The first call of KS_createSharedMem allocates the memory area and initializes it with 0. All following calls for the same name only returns the pointer to the already allocated block of memory. So it is possible to share memory between applications and/or to count the requests for the memory area.