Changeset 300 for trunk/src


Ignore:
Timestamp:
Mar 9, 2006 1:10:14 PM (18 years ago)
Author:
cxsong
Message:

updated with new read methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mesh/grid1d.cc

    r297 r300  
    9393        int nbytes = numBytes();
    9494
    95         // total length = tagEncode + tagCompress + num + array data
    96         if ( (buf = (char*) malloc(nbytes)) == NULL) {
    97                 RpAppendErr("RpGrid1d::serialize: malloc failed");
     95        if ( (buf = new char[nbytes]) == NULL) {
     96                RpAppendErr("RpGrid1d::serialize: new char[] failed");
    9897                RpPrintErr();
    9998                return buf;
     
    122121        char * ptr = buf;
    123122
    124         writeHeader(ptr, RpGrid1d_current_version, nbytes);
     123        // write object header (version and typename)
     124        writeRpHeader(ptr, RpGrid1d_current_version, nbytes);
    125125        ptr += HEADER_SIZE + sizeof(int);
    126126       
    127         writeObjectName(ptr, m_name);
     127        // write object name and its length
     128        writeString(ptr, m_name);
    128129        ptr += m_name.size() + sizeof(int);
    129130
    130         // copy int (number of points)
    131 
     131        // write number of points and array data
    132132        writeArrayDouble(ptr, m_data, m_data.size());
    133133
     
    148148        int nbytes;
    149149
    150         readHeader(ptr, header, nbytes);
     150        readRpHeader(ptr, header, nbytes);
    151151        ptr += HEADER_SIZE + sizeof(int);
    152152       
     
    169169        // parse object name and store name in m_name
    170170
    171         readObjectName(ptr, m_name);
     171        readString(ptr, m_name);
    172172        ptr += sizeof(int) + m_name.size();
    173173       
    174174        int npts;
    175         readArrayDouble(ptr, &m_data, npts);
     175        readArrayDouble(ptr, m_data, npts);
    176176
    177177        return RP_SUCCESS;
     
    196196
    197197        DataValType* xy;
    198         if ( (xy = new DataValType(npts)) == NULL) {
     198        if ( (xy = new DataValType[npts]) == NULL) {
    199199                RpAppendErr("RpGrid1d::data: mem alloc failed");
    200200                RpPrintErr();
     
    282282                + m_data.size() * sizeof(DataValType);
    283283
     284#ifdef DEBUG
     285        printf("RpGrid1d::numBytes returns %d\n", nbytes);
     286#endif
    284287        return nbytes;
    285288}
Note: See TracChangeset for help on using the changeset viewer.