Changeset 4830 for nanovis/branches/1.1


Ignore:
Timestamp:
Dec 10, 2014, 1:32:28 AM (5 years ago)
Author:
ldelgass
Message:

Preallocate full size Rappture buffer for data payloads

Location:
nanovis/branches/1.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.1/Command.cpp

    r4829 r4830  
    12111211    }
    12121212    const char *tag = Tcl_GetString(objv[4]);
    1213     Rappture::Buffer buf;
     1213
     1214    Rappture::Buffer buf(nbytes);
    12141215    if (GetDataStream(interp, buf, nbytes) != TCL_OK) {
    12151216        return TCL_ERROR;
    12161217    }
    1217     const char *bytes;
    1218     size_t nBytes;
    1219 
    1220     bytes = buf.bytes();
    1221     nBytes = buf.size();
     1218    const char *bytes = buf.bytes();
     1219    size_t nBytes = buf.size();
    12221220
    12231221    TRACE("Checking header[%.20s]", bytes);
     
    12271225    if ((nBytes > 5) && (strncmp(bytes, "<HDR>", 5) == 0)) {
    12281226        TRACE("ZincBlende Stream loading...");
    1229          //std::stringstream fdata(std::ios_base::out|std::ios_base::in|std::ios_base::binary);
    1230         //fdata.write(buf.bytes(),buf.size());
    1231         //vol = NvZincBlendeReconstructor::getInstance()->loadFromStream(fdata);
    1232 
    1233         volume = NvZincBlendeReconstructor::getInstance()->loadFromMemory((void*) buf.bytes());
     1227        volume = NvZincBlendeReconstructor::getInstance()->loadFromMemory(buf.bytes());
    12341228        if (volume == NULL) {
    12351229            Tcl_AppendResult(interp, "can't get volume instance", (char *)NULL);
     
    12751269        }
    12761270        TRACE("DX loading...");
    1277         std::stringstream fdata;
    1278         fdata.write(bytes, nBytes);
    12791271        if (nBytes <= 0) {
    12801272            ERROR("data buffer is empty");
    12811273            abort();
    12821274        }
     1275        std::stringstream fdata;
     1276        fdata.write(bytes, nBytes);
    12831277        Rappture::Outcome context;
    12841278        volume = load_dx_volume_stream(context, tag, fdata);
     
    12961290        volume->visible(true);
    12971291
    1298         char info[1024];
    1299         ssize_t nWritten;
    1300 
    13011292        if (Volume::updatePending) {
    13021293            NanoVis::setVolumeRanges();
    13031294        }
    13041295
    1305         // FIXME: strlen(info) is the return value of sprintf
    1306         sprintf(info, "nv>data tag %s min %g max %g vmin %g vmax %g\n", tag,
    1307                 volume->wAxis.min(), volume->wAxis.max(),
    1308                 Volume::valueMin, Volume::valueMax);
    1309         nWritten  = write(1, info, strlen(info));
    1310         assert(nWritten == (ssize_t)strlen(info));
     1296        char info[1024];
     1297        int cmdLength =
     1298            sprintf(info, "nv>data tag %s min %g max %g vmin %g vmax %g\n", tag,
     1299                    volume->wAxis.min(), volume->wAxis.max(),
     1300                    Volume::valueMin, Volume::valueMax);
     1301        ssize_t nWritten = write(1, info, (size_t)cmdLength);
     1302        if (nWritten != (ssize_t)cmdLength) {
     1303            ERROR("Short write");
     1304            return TCL_ERROR;
     1305        }
    13111306    }
    13121307    return TCL_OK;
     
    17091704    const char *tag = Tcl_GetString(objv[4]);
    17101705
    1711     Rappture::Buffer buf;
     1706    Rappture::Buffer buf(nBytes);
    17121707    if (GetDataStream(interp, buf, nBytes) != TCL_OK) {
    17131708        return TCL_ERROR;
  • nanovis/branches/1.1/FlowCmd.cpp

    r4613 r4830  
    231231        return TCL_ERROR;
    232232    }
    233     Rappture::Buffer buf;
     233    Rappture::Buffer buf(nBytes);
    234234    TRACE("Flow data loading bytes: %d components: %d", nBytes, nComponents);
    235235    if (GetDataStream(interp, buf, nBytes) != TCL_OK) {
    236236        return TCL_ERROR;
    237237    }
     238    char *bytes = (char *)buf.bytes();
     239    size_t length = buf.size();
     240
    238241    Rappture::Unirect3d *dataPtr;
    239242    dataPtr = new Rappture::Unirect3d(nComponents);
    240243
    241244    Flow *flow = (Flow *)clientData;
    242     size_t length = buf.size();
    243     char *bytes = (char *)buf.bytes();
    244245    if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) {
    245246        if (!dataPtr->importDx(result, nComponents, length - 4, bytes + 4)) {
     
    292293    {
    293294        char info[1024];
    294         ssize_t nWritten;
    295         size_t length;
    296 
    297         length = sprintf(info, "nv>data tag %s min %g max %g\n",
    298                          flow->name(), dataPtr->magMin(), dataPtr->magMax());
    299         nWritten  = write(1, info, length);
    300         assert(nWritten == (ssize_t)strlen(info));
     295        int length =
     296            sprintf(info, "nv>data tag %s min %g max %g\n",
     297                    flow->name(), dataPtr->magMin(), dataPtr->magMax());
     298        ssize_t nWritten = write(1, info, (size_t)length);
     299        if (nWritten != (ssize_t)length) {
     300            ERROR("Short write");
     301            return TCL_ERROR;
     302        }
    301303    }
    302304    NanoVis::eventuallyRedraw(NanoVis::MAP_FLOWS);
  • nanovis/branches/1.1/NvZincBlendeReconstructor.cpp

    r3502 r4830  
    369369
    370370ZincBlendeVolume *
    371 NvZincBlendeReconstructor::loadFromMemory(void *dataBlock)
     371NvZincBlendeReconstructor::loadFromMemory(const void *dataBlock)
    372372{
    373373    ZincBlendeVolume *volume = NULL;
     
    377377    int version = 1;
    378378
    379     unsigned char *stream = (unsigned char *)dataBlock;
     379    const unsigned char *stream = (const unsigned char *)dataBlock;
    380380    char str[5][20];
    381381    do {
     
    469469}
    470470
    471 void NvZincBlendeReconstructor::getLine(unsigned char*& stream)
     471void NvZincBlendeReconstructor::getLine(const unsigned char*& stream)
    472472{
    473473    char ch;
  • nanovis/branches/1.1/NvZincBlendeReconstructor.h

    r3502 r4830  
    4141    ZincBlendeVolume *loadFromStream(std::istream& stream);
    4242
    43     ZincBlendeVolume *loadFromMemory(void *dataBlock);
     43    ZincBlendeVolume *loadFromMemory(const void *dataBlock);
    4444
    4545    /**
     
    7373     */
    7474    void getLine(std::istream& stream);
    75     void getLine(unsigned char*& stream);
     75    void getLine(const unsigned char*& stream);
    7676
    7777    char buff[255];
Note: See TracChangeset for help on using the changeset viewer.