Changes between Version 3 and Version 4 of C++ API
- Timestamp:
- 09/10/12 11:19:57 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
C++ API
v3 v4 30 30 31 31 The 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=|| 33 33 ||{{{MUSCLE_DOUBLE}}}||{{{double *}}}||{{{double[]}}}||134e6 values || 34 34 ||{{{MUSCLE_FLOAT}}}||{{{float *}}}||{{{float[]}}}||268e6 values|| … … 41 41 The type {{{MUSCLE_COMPLEX}}} is only available for C++ code. 42 42 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: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 allocate the memory. In both cases, the memory must be freed by the user. For example: 44 44 {{{ 45 45 size_t sz = 100; … … 48 48 for (int i = 0; !MUSCLE_Will_Stop(); i++) { 49 49 MUSCLE_Receive("exitName", data, &sz, MUSCLE_DOUBLE); 50 // sz will be set to the actual size of the received message 50 51 // do something with the data 51 52 } … … 63 64 } 64 65 }}} 66 The 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 68 The {{{MUSCLE_Send}}} command can only be used one way. 69 {{{ 70 double data[100]; 71 size_t sz = 100; 72 for (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