Proposed Addition to SDK - Global Data

Introduction

One problem with MMF is that it does not provide an easy way to handle global objects. The best you can do is store some data in special section of MMF and then have retrieve that data later. This is not the best way to do things. What follows is my proposed changes to the SDK to help make global data universal.

How it Would Work

This process needs to be as simple as humanly possible. That is the best way to ensure the extension developers will use it. Here is the process that developers would need to follow to use global data:

  1. Define a precompiler constant (maybe #define USEGLOBALDATA or some such).
  2. Add any data that is to be global to the GLOBALDATA structure (which comes predefined).
  3. Add an option to the edit dialog of the object that allows to user to toggle globality.
  4. Add code to the DestroyGlobalData() function to de-allocate memory referenced by the global data.

That's all there is to it, so using my process for global data will be very easy.

Changes to the SDK

New Precompiler Constants

USEGLOBALDATA

DEFAULTGARRAYSIZE

New Structures

typedef struct tagGDATA
{
char szName[OI_NAMESIZE + 1]; // Name of the object
unsigned int nIndex; // Index in the global array
bool bGlobal; // Whether or not this object is actually global
// The user's global data goes here
} GLOBALDATA;
typedef GLOBALDATA _far * LPGDATA;

The above structure would be used by the developer to store their global data. The two provided fields are required by internal functions and should never be changed by the user.

typedef struct
{
unsigned int nApplications; // Used to keep track of how many applications have been opened (each sub-application is a new application). When the count reaches 0, all global data is destroyed.
LPGDATA * papgdGlobalData; // Used to store the global data. This array will have some default size (maybe 10) and will be resized as needed.
unsigned int nGlobalSize; // The size of the global data array.
unsigned int gnGlobalCount; // The number of actual elements in the global data array.
} GLOBALARRAY;

The above structure is used to maintain the array of global data.

New Global Variables

GLOBALARRAY ggaGlobalData

New Functions

LPGDATA GetGlobalData(LPRDATA rdPtr, bool vbGlobal)

LPGDATA GetGlobalData(char * vpacName, bool vbGlobal)

void UngetGlobalData(LPGDATA gdPtr)

void DestroyGlobalData(LPGDATA gdPtr)

LPGDATA GetFromGlobalArray(char * vpszName)

void RemoveFromGlobalArray(unsigned int vnIndex)

void DestoryGlobalArray()

Modifications to Existing Structures

RUNDATA

EDITDATA

Modifications to Existing Functions

CreateObject

CreateRunObject

DestroyRunObject

Initialize

Free