buffer

Copying bytes in Python from Numpy array into string or bytearray

不想你离开。 提交于 2020-01-03 03:19:06
问题 I am reading data from an UDP socket in a while loop. I need the most efficient way to 1) Read the data (*) (that's kind of solved, but comments are appreciated) 2) Dump the (manipulated) data periodically in a file (**) (The Question) I am anticipating a bottleneck in the numpy's "tostring" method. Let's consider the following piece of (an incomplete) code: import socket import numpy nbuf=4096 buf=numpy.zeros(nbuf,dtype=numpy.uint8) # i.e., an array of bytes f=open('dump.data','w')

Passing 2 stdin arguments to a ImageMagick child_process

↘锁芯ラ 提交于 2020-01-02 07:36:08
问题 I have certain limitations that I won't specify that require me to use ImageMagick as a child-process. I have multiple base 64 strings of jpg files which I want ImageMagick to process. Specifically I want ImageMagick to join the jpg files together. If I had 2 regular jpg files then from the command line I would use the following format. node convert in_1.jpg in_2.jpg +append out.jpg in a js file I would use var spawn, magicCommands, imagic; spawn = require('child_process').spawn;

How to effectively swap OpenCL memory buffers?

99封情书 提交于 2020-01-02 03:39:06
问题 Exactly as the title suggests I am looking for how to effectively swap two OpenCL buffers. My kernel uses two gloabl buffers, one as input and one as output. However, I invoke my kernel in a for loop with the same NDRange, each time setting the kernel arguments, enqueueing the kernel, and swapping the buffers because the previous output buffer will be the input buffer seed for the next iteration. What is the appropriate way here, to swap these two buffers? I imagine that copying the buffer

C scanf in a loop with invalid input

我是研究僧i 提交于 2020-01-02 00:23:09
问题 I have to do this if statement , or it turns in an infinite loop if some invalid input like "17d" is set. Why ? I think something with buffer but scanf reads from stdin not from stream? int age; while (age != 0) { printf("How old are you? "); if(scanf("%d", &age) > 0) { printf("You are %d years old!\n", age); } else { break; } } 回答1: When scanf does not succeed, it leaves the input in the stream. You need to ignore the rest of the line and ask the user to provide the input again. You can add

scanf/getchar working correctly only first time through loop? [duplicate]

夙愿已清 提交于 2020-01-01 19:43:30
问题 This question already has answers here : Why doesn't getchar() wait for me to press enter after scanf()? (10 answers) Closed 9 months ago . I'm trying to have the user enter in a number as many times as they want (and create a linked list node for each of the numbers). However, I've tried multiple method of clearing the character input buffer but to no avail. Strangely, the code will execute once through but not execute correctly the second. For example, with the code below, the terminal

How to effectively draw on desktop in C#?

落爺英雄遲暮 提交于 2020-01-01 09:07:09
问题 I want to draw directly on the desktop in C#. From searching a bit, I ended up using a Graphics object from the Desktop HDC (null). Then, I painted normally using this Graphics object. The problem is that my shapes get lost when any part of the screen is redrawn. I tried a While loop, but it actually ends up drawing as fast as the application can, which is not the update rate of the desktop. Normally, I would need to put my drawing code in a "OnPaint" event, but such thing does not exist for

How to convert buffer to stream in Nodejs

早过忘川 提交于 2020-01-01 08:49:21
问题 I confront with a problem about converting buffer into stream in Nodejs.Here is the code: var fs = require('fs'); var b = Buffer([80,80,80,80]); var readStream = fs.createReadStream({path:b}); The code raise an exception: TypeError: path must be a string or Buffer However the document of Nodejs says that Buffer is acceptable by fs.createReadStream(). fs.createReadStream(path[, options])   path <string> | <Buffer> | <URL>   options <string> | <Object> Anybody could answer the question? Thanks

C# Copy variables into buffer without creating garbage?

佐手、 提交于 2020-01-01 04:57:11
问题 Is it possible in C# .Net (3.5 and above) to copy a variable into a byte[] buffer without creating any garbage in the process? For instance: int variableToCopy = 9861; byte[] buffer = new byte[1024]; byte[] bytes = BitConverter.GetBytes(variableToCopy); Buffer.BlockCopy(bytes, 0, buffer, 0, 4); float anotherVariableToCopy = 6743897.6377f; bytes = BitConverter.GetBytes(anotherVariableToCopy); Buffer.BlockCopy(bytes, 0, buffer, 4, sizeof(float)); ... creates the byte[] bytes intermediary object

Fully buffer video in Chrome

风格不统一 提交于 2020-01-01 04:42:26
问题 Is it possible to fully buffer HTML5 video in Chrome (and Opera)? I host the movie in .mp4 and .webm on amazon S3. In HTML I use standard <video> tag. The server responds with status 206 Partial Content . It is great, as it allows the browser to download any part of the video but I need to be able to seek instantly to any part of the file. I tried: .PROGRESS event. When Chrome stops buffering the first part, the connection is killed. The next parts are downloaded in new connection, so

UDP Server Socket Buffer Overflow

喜你入骨 提交于 2020-01-01 03:28:05
问题 I am writing a C++ application on Linux. My application has a UDP server which sends data to clients on some events. The UDP server also receives some feedback/acknowledgement back from the clients. To implement this application I used a single UDP Socket(e.g. int fdSocket ) to send and receive data from all the clients. I bound this socked to port 8080 and have set the socket into NON_BLOCKING mode. I created two threads. In one thread I wait for some event to happen, if an event occurs then