While c-treeDB API performs all record buffer memory management dynamically, the API is flexible enough to permit the user to perform record buffer memory management. ctdbSetRecordBuffer() allows developers to control how c-treeDB API performs data record memory management.
/* define my own static record structure */
typedef struct
{
NINT id;
TEXT name[32];
CTDATE birthday;
} MyRecordDef;
/* declare my own record buffer variable */
MyRecordDef MyRecord;
/* declare and allocate a record handle */
CTHANDLE hRecord = ctdbAllocRecord(hTable);
/* tell record handle to use my own record variable */
if (ctdbSetRecordBuffer(hRecord, &MyRecord, sizeof(MyRecord), CTRECBUF_STATIC) != CTDBRET_OK)
printf("Set record buffer failed\n");
ctdbSetRecordBuffer() takes as parameters the record handle, a user-supplied record buffer address, the size of the buffer, and the record buffer mode.
The valid record buffer modes are:
Mode |
Explanation |
---|---|
CTRECBUF_AUTO |
This is the default record buffer management mode. When a record handle is allocated by calling ctdbAllocRecord(), the record buffer management mode is set to CTRECBUF_AUTO. This mode implies that the c-treeDB API will perform the data record buffer management dynamically. |
CTRECBUF_STATIC |
When this mode is set, the data record buffer is set to pBuffer and the user is responsible to supply a buffer that is large enough to perform all record operations for the table. |
CTRECBUF_RAW |
OR with CTRECBUF_STATIC to indicate the record manager is not allowed to update the internal control structures of the record buffer for variable-length records. |
To reset the record buffer management back to CTRECBUF_AUTO, after it has been changed to CTRECBUF_STATIC, call ctdbSetRecordBuffer() passing the record handle, NULL buffer, with length of zero and CTRECBUF_AUTO mode.
/* reset the record buffer to automatic */
if (ctdbSetRecordBuffer(hRecord, NULL, 0, CTRECBUF_AUTO) != CTDBRET_OK)
printf("Reset record buffer failed\n");