Changes between Version 3 and Version 4 of C++ API

Show
Ignore:
Timestamp:
09/10/12 11:19:57 (12 years ago)
Author:
jorisborgdorff
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • C++ API

    v3 v4  
    3030 
    3131The send and receive functions can transport several datatypes, which are enumerated in {{{muscle2/muscle_types.h}}}. For reference, it takes the following datatypes 
    32 ||={{{muscle_datatype_t}}}=||=C data type=||= Java data type =||=maximum size=|| 
     32||={{{muscle_datatype_t}}}=||=C/C++ data type=||= Java data type =||=maximum size=|| 
    3333||{{{MUSCLE_DOUBLE}}}||{{{double *}}}||{{{double[]}}}||134e6 values || 
    3434||{{{MUSCLE_FLOAT}}}||{{{float *}}}||{{{float[]}}}||268e6 values|| 
     
    4141The type {{{MUSCLE_COMPLEX}}} is only available for C++ code. 
    4242 
    43 Receiving a message can be done in two ways: either the memory is initialized beforehand and the buffer size is given as the third argument, or a 0 pointer is passed, in which case MUSCLE will initialize the memory. In both cases, the memory must be freed by the user. For example: 
     43Receiving a message can be done in two ways: either the memory is initialized beforehand and the buffer size is given as the third argument, or a 0 pointer is passed, in which case MUSCLE will allocate the memory. In both cases, the memory must be freed by the user. For example: 
    4444{{{ 
    4545size_t sz = 100; 
     
    4848    for (int i = 0; !MUSCLE_Will_Stop(); i++) { 
    4949        MUSCLE_Receive("exitName", data, &sz, MUSCLE_DOUBLE); 
     50        // sz will be set to the actual size of the received message 
    5051        // do something with the data 
    5152    } 
     
    6364} 
    6465}}} 
     66The first example will only work if you know the upper bound of received message size in advance. In this way, memory is only allocated once per submodel run. The second example is safer since MUSCLE will allocate the necessary data for you based on the message size. It does mean that new memory is allocated each message. 
     67 
     68The {{{MUSCLE_Send}}} command can only be used one way. 
     69{{{ 
     70double data[100]; 
     71size_t sz = 100; 
     72for (int i = 0; !MUSCLE_Will_Stop(); i++) { 
     73    // do something with the data... 
     74    // send the data 
     75    MUSCLE_Send("entranceName", data, sz, MUSCLE_DOUBLE); 
     76} 
     77// data is on the stack; it will be freed automatically 
     78}}} 
     79 
     80== C++ API == 
     81 
     82