Memory Management Subsystem



Though small, this is the heart of what makes NAS GUI possible in C. This system allows for storing infinite variables and data types within the dialog structure without cluttering up any dp pointers. This system can also be used to share and send data between procs.

void init_mem();
Initializes the memory system tables and variables. There is no return value since there is not the possibility of error.

void *create_mem(void *fun, int id, void *data, int type);
Creates a memory segment that points to any type of data. The fun field takes in a pointer to a dialog procedure, id must be a unique identifier for that procedure, and type can be any one of these defines:

        MEM_ALLOCATED - Data was created using malloc or calloc
        MEM_BITMAP    - Data is a bitmap pointer
        MEM_STATIC    - Data is static and will not be freed
Even though id must be a unique identifier per procedure, you can have the same id used in two separate procedures, this is because both the function pointer and id are used to determine what memory segment will be fetched with get_mem(). This function returns the data pointer. For example if you wanted to create an array of 5 integers unique to a dialog procedure with and id of 1 the call would look as follows:

        int *my_ints = (int*)create_mem(d, 1, malloc(sizeof(int)*5),
                                        MEM_ALLOCATED);

void *get_mem(void *fun, int id);
Retrieves the memory segment for the procedure that matches the fun field and the id that was sent in on the call to create_mem().

void destroy_mem(void *fun, int id);
Destroys the memory segment for a procedure that matches the id that was sent in on the call to create_mem().

void free_mem();
Destroys all memory used by the memory management system. Useful to clean up before shutting down, this however is called on nas_exit().


Back to Contents