DataObject::GetInternalDataBuffer

Description

Get internal Data buffer of Column or MatrixObject.

Syntax

LPVOID GetInternalDataBuffer( int * pnElementSize = NULL, uint * pnNumElements = NULL )

Parameters

pnElementSize
[output] if it is not NULL, get the size of data type of element.
pnNumElements
[output] if it is not NULL, get the number of element in the object.

Return

If the data type is mixed, return NULL, otherwise return internal data buffer.

Examples

EX1

void DataObject_GetInternalDataBuffer_Ex1()
{
        Worksheet wks = Project.ActiveLayer();
        if(wks)
        {
                Column col(wks, 0); // first column
                
                if( col )
                {                     
                        int nElementSize;
                        uint nNum;
                        LPVOID pData = col.GetInternalDataBuffer(&nElementSize, &nNum);                           
                        if(NULL == pData)
                                out_str("return NULL if col is Text type or mixed type");
                        else
                        {
                                if(0 != nNum)
                                {
                                        double *pTemp = (double*)pData; // cast to double since cannot direclty access the value of void type pointer point to 
                                        *pTemp = 0.5; // change the value of first item 
                                        col.ReleaseBuffer(); // after call this, first row of first column will change to 0.5
                                }
                        }
                }
        }     
}

EX2

//This example show how to set a column to two-byte integers and get its 
//pointer to assign values to

void DataObject_GetInternalDataBuffer_Ex2(int nRows = 10000)
{
        Worksheet wks = Project.ActiveLayer();
        if(wks)
        {
                Column col(wks, 0); // first column
                if( col )
                {
                        col.SetFormat(OKCOLTYPE_NUMERIC);
                        col.SetInternalData(FSI_SHORT);
                        col.SetUpperBound(nRows-1);//index of last row, 0 offset
                        int nElementSize;
                        uint nNum;
                        LPVOID pData = col.GetInternalDataBuffer(&nElementSize, &nNum);
                        printf("nElementSize = %d, Num Rows = %d\n", nElementSize, nNum);
                        short* psBuff = (short*)pData;
                        // OC loop is still slow, but you might pass this pointer to your DLL
                        // for much faster manipulation, here we just show that the pointer works
                        for(int ii = 0; ii < nRows; ii++, psBuff++)
                        {
                                *psBuff = (ii+1)*2;
                        }
                        col.ReleaseBuffer();
                }
        }     
}

EX3

//This example will double all the cell's value of the active matrixobject
void DataObject_GetInternalDataBuffer_Ex3()
{
        //assume there exists an active matrixsheet
        MatrixLayer mtx = Project.ActiveLayer();
        if ( !mtx )
        {
                printf("Can not get active matrixsheet");
                return;
        }
        MatrixObject mo = mtx.MatrixObjects(0); //get first matrix object
        int nEleSize;
        uint nSize;
        mo.SetFormat(OKCOLTYPE_NUMERIC);
        mo.SetInternalData(FSI_SHORT);
        LPVOID lpData = mo.GetInternalDataBuffer(&nEleSize, &nSize);
        short* psData = (short*)lpData;
        for ( int ii = 0; ii < nSize; ii++, psData++)
        {
                *psData = *psData * 2;
        }
        mo.ReleaseBuffer();
        return;
}

Remark

You need to call SetUpperBound in a column before you can access the data, unless the column already has upper bound set.

See Also

DataObject::ReleaseBuffer

header to Include

origin.h