Define the SPUPad content
As the first step in creating a SPUPad within your C++ program, identify the types of data that will be saved in your SPUPad. If you plan to have several different types of data in the SPUPad, consider creating a structure type to define the content. (In the SPUPad examples, this structure is called the Root structure type. Each SPUPad gives you access to a portion of memory that can be thought of as the root of a tree. Basically, all the objects in the SPUPad can be reached only through the root object.)
In a root object, you can store a single object (such as int, double), an array (such as char*, int*), or a structure. As an example, assume that you plan to use a SPUPad to store a string of characters. The Root structure might contain a pointer to the string, and perhaps a size value to help set some boundaries for the string size and the memory that is consumed by the SPUPad.
#include "udxinc.h"
#include <string.h>
using namespace nz::udx;
struct Root
{
char* data;
int size;
};struct MyValue
{
char* name;
int value;
};
struct MyLookup
{
MyValue *values;
int numallocated;
int numused;
};In this example, the root object is an instance of MyLookup, which can contain an arbitrary number of MyValue objects. All of the objects, plus the char* strings, are allocated through the SPUPad allocation mechanisms, but the only way to get to a value (or the name in a value) is through the MyLookup root object.
If you create multiple C++ files to define UDXs that manipulate the data in the same SPUPad, make sure that you repeat your Root structure definition in each C++ file. If you define a number of common structures or definitions, you can create an include file to define all these objects in one location.
Although there is no maximum number of objects that a SPUPad can hold, try to limit the number of objects that you create to only those objects that you really need. The SPUPad tracks each object by using a pointer per object, which adds to the memory consumed by the SPUPad.