What is an effective way to convert a shared memory-mapped system to another data access model?

Posted by Rob Jones on Programmers See other posts from Programmers or by Rob Jones
Published on 2011-08-14T17:41:07Z Indexed on 2011/11/16 2:07 UTC
Read the original article Hit count: 279

Filed under:
|

I have a code base that is designed around shared memory. Each process that needs to access the memory maps it into its own address space. The data structures in the shared memory are directly accessed, that is, there is no API. For example:

Assume the following:

typedef struct {
  int x;
  int y;
  struct {
    int a;
    int b;
  } z;
} myStruct;

myStruct s;

Then a process might access this structure as:

myStruct *s = mapGlobalMem();

And use it as:

int tmpX = s->x;

The majority of the information in the global structure is configuration information that is set once and read many times. I would like to store this information in a database and develop an API to access the database. The problem is, these references are sprinkled throughout the code. I need a way to parse the code and identify global structure references that will need to be refactored.

I've looked into using ANTLR to create a parser that will identify references to a small set of structures and enter them into a custom symbol table. I could then use this symbol table to identify which source files need to be refactored. It looks like a promising approach.

What other approaches are there? Of course, I'm looking for a programmatic approach. There are far too many source files to examine each one visually.

This is all ordinary ANSI C. Nothing else.

© Programmers or respective owner

Related posts about c

    Related posts about refactoring