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

Preallocate full size Rappture buffer for data payloads

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.