What is the recommended way of allocating memory for a typed memory view?

Look here for an answer. The basic idea is that you want cpython.array.array and cpython.array.clone (not cython.array.*): from cpython.array cimport array, clone # This type is what you want and can be cast to things of # the “double[:]” syntax, so no problems there cdef array[double] armv, templatemv templatemv = array(‘d’) # This is fast … Read more

std::cout won’t print

Make sure you flush the stream. This is required because the output streams are buffered and you have no guarantee over when the buffer will be flushed unless you manually flush it yourself. std::cout << “Hello” << std::endl; std::endl will output a newline and flush the stream. Alternatively, std::flush will just do the flush. Flushing … Read more

Flushing buffers in C

Flushing the output buffers: printf(“Buffered, will be flushed”); fflush(stdout); // Prints to screen or whatever your standard out is or fprintf(fd, “Buffered, will be flushed”); fflush(fd); //Prints to a file Can be a very helpful technique. Why would you want to flush an output buffer? Usually when I do it, it’s because the code is … Read more

Buffered files (for faster disk access)

Windows file caching is very effective, especially if you are using Vista or later. TFileStream is a loose wrapper around the Windows ReadFile() and WriteFile() API functions and for many use cases the only thing faster is a memory mapped file. However, there is one common scenario where TFileStream becomes a performance bottleneck. That is … Read more

Ring Buffer in Java

Consider CircularFifoBuffer from Apache Common.Collections. Unlike Queue you don’t have to maintain the limited size of underlying collection and wrap it once you hit the limit. Buffer buf = new CircularFifoBuffer(4); buf.add(“A”); buf.add(“B”); buf.add(“C”); buf.add(“D”); //ABCD buf.add(“E”); //BCDE CircularFifoBuffer will do this for you because of the following properties: CircularFifoBuffer is a first in first … Read more

Convert a binary NodeJS Buffer to JavaScript ArrayBuffer

Instances of Buffer are also instances of Uint8Array in node.js 4.x and higher. Thus, the most efficient solution is to access the buf.buffer property directly, as per https://stackoverflow.com/a/31394257/1375574. The Buffer constructor also takes an ArrayBufferView argument if you need to go the other direction. Note that this will not create a copy, which means that … Read more

Force line-buffering of stdout in a pipeline

you can try stdbuf $ stdbuf –output=L ./a | tee output.txt (big) part of the man page: -i, –input=MODE adjust standard input stream buffering -o, –output=MODE adjust standard output stream buffering -e, –error=MODE adjust standard error stream buffering If MODE is ‘L’ the corresponding stream will be line buffered. This option is invalid with standard … Read more