Category: Programming

Move semantics vs Copy semantics; And when to use them.

#include <vector> #include <iostream> class Semantics { public: // Pass by value to store a new copy using std::move // (rvalue is moved, lvalue is copied) Semantics(std::vector<int> in) : m_v(std::move(in)) { } std::vector<int> get() const { return m_v; } // Pass by reference to modify an `out` parameter: lvalue only void append(std::vector<int> &out) { out.insert(out.end(),…

Read the full article

Using struct module to send/receive floats over TCP socket with Python

Server This sends 10 floats at a time, on a loop. The transmit data type is determined by the’=%sf’ % payload.sizeformat string passed tostruct.pack. import socket from struct import * import numpy as np #number of floats we are sending payload_size = 10 payload = np.linspace(0, 10, payload_size) print(‘Sending {}’.format(payload)) #pack the floats as bytes…

Read the full article