C++ std::string append vs push_back()

In C++03 (for which most of “cplusplus.com”‘s documentation is written), the complexities were unspecified because library implementers were allowed to do Copy-On-Write or “rope-style” internal representations for strings. For instance, a COW implementation might require copying the entire string if a character is modified and there is sharing going on. In C++11, COW and rope … Read more

Append 2D array to 3D array, extending third dimension

Use dstack: >>> np.dstack((A, B)).shape (480, 640, 4) This handles the cases where the arrays have different numbers of dimensions and stacks the arrays along the third axis. Otherwise, to use append or concatenate, you’ll have to make B three dimensional yourself and specify the axis you want to join them on: >>> np.append(A, np.atleast_3d(B), … Read more

Appending to an ObjectOutputStream

Here’s the trick: subclass ObjectOutputStream and override the writeStreamHeader method: public class AppendingObjectOutputStream extends ObjectOutputStream { public AppendingObjectOutputStream(OutputStream out) throws IOException { super(out); } @Override protected void writeStreamHeader() throws IOException { // do not write a header, but reset: // this line added after another question // showed a problem with the original reset(); } … Read more