buffer

Threadsafe FIFO Queue/Buffer

别说谁变了你拦得住时间么 提交于 2019-12-30 06:18:49
问题 I need to implement a sort of task buffer. Basic requirements are: Process tasks in a single background thread Receive tasks from multiple threads Process ALL received tasks i.e. make sure buffer is drained of buffered tasks after a stop signal is received Order of tasks received per thread must be maintained I was thinking of implementing it using a Queue like below. Would appreciate feedback on the implementation. Are there any other brighter ideas to implement such a thing? public class

C++ Buffer Overflow

旧街凉风 提交于 2019-12-30 03:33:08
问题 I'm trying to teach myself about buffer overflows and exploitation in C++. I'm an intermediate C++ guy, at best, so bear with me. I've followed a few tutorials, but here's some example code to illustrate my question: #include <string> #include <iostream> using namespace std; int main() { begin: int authentication = 0; char cUsername[10], cPassword[10]; char cUser[10], cPass[10]; cout << "Username: "; cin >> cUser; cout << "Pass: "; cin >> cPass; strcpy(cUsername, cUser); strcpy(cPassword,

Adjust the length of an AudioUnit Buffer

萝らか妹 提交于 2019-12-30 02:31:08
问题 my Problem concerns AudioUnits. In order to design a voicechanging App for iPhone (with Objective-C xCode) i use RemoteIO audioUnit sample from this website: http://atastypixel.com/blog/using-remoteio-audio-unit/ The audioUnit buffers are set to a length of 256 samples. For my project i need alot more (about 22050). The quoted page says that the length of the audioUnit buffers can be adjusted like this: float aBufferLength = 0.005; // In seconds AudioSessionSetProperty(kAudioSessionProperty

How to display nodejs raw Buffer data as Hex string

丶灬走出姿态 提交于 2019-12-29 11:40:48
问题 The following code uses SerialPort module to listen to data from a bluetooth connection. I am expecting to see a stream of data in Hexadecimal format printed in console. But the console just shows some weird simbols. I want to know how can I decode and display the data in console. var serialPort = new SerialPort("/dev/tty.EV3-SerialPort", { parser: SP.parsers.raw }, false); // this is the openImmediately flag [default is true] serialPort.open(function () { console.log('open'); serialPort.on(

.NET: Inject Data into Input-Buffer of Process

跟風遠走 提交于 2019-12-29 09:06:30
问题 I need to automate an command line application. It asks the user to enter a password. All my approches to send the password via STDIN failed. Now I am trying to do this with an wrapper-programm using .NET. I am starting the application creating a new process, setting the StartInfo -properties and then start the process: Dim app_path As String Dim app_args As String Dim myProcess As Process = New Process() myProcess.StartInfo.FileName = app_path myProcess.StartInfo.Arguments = app_args

Determining Appropriate Buffer Size

霸气de小男生 提交于 2019-12-29 07:58:57
问题 I am using ByteBuffer.allocateDirect() to allocate some buffer memory for reading a file into memory and then eventually hashing that files bytes and getting a file hash (SHA) out of it. The input files range greatly in size, anywhere from a few KB's to several GB's. I have read several threads and pages (even some on SO) regarding selecting a buffer size. Some advised trying to select one that the native FileSystem uses in an attempt to minimalize chances of a read operation for a partial

Using read() directly into a C++ std:vector

强颜欢笑 提交于 2019-12-29 05:46:28
问题 I'm wrapping up user space linux socket functionality in some C++ for an embedded system (yes, this is probably reinventing the wheel again). I want to offer a read and write implementation using a vector. Doing the write is pretty easy, I can just pass &myvec[0] and avoid unnecessary copying. I'd like to do the same and read directly into a vector, rather than reading into a char buffer then copying all that into a newly created vector. Now, I know how much data I want to read, and I can

Limiting TCP sends with a “to-be-sent” queue and other design issues

寵の児 提交于 2019-12-29 00:41:49
问题 This question is the result of two other questions I've asked in the last few days. I'm creating a new question because I think it's related to the "next step" in my understanding of how to control the flow of my send/receive, something I didn't get a full answer to yet. The other related questions are: An IOCP documentation interpretation question - buffer ownership ambiguity Non-blocking TCP buffer issues In summary, I'm using Windows I/O Completion Ports. I have several threads that

Java - Convert int to Byte Array of 4 Bytes? [duplicate]

点点圈 提交于 2019-12-28 03:32:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Convert integer into byte array (Java) I need to store the length of a buffer, in a byte array 4 bytes large. Pseudo code: private byte[] convertLengthToByte(byte[] myBuffer) { int length = myBuffer.length; byte[] byteLength = new byte[4]; //here is where I need to convert the int length to a byte array byteLength = length.toByteArray; return byteLength; } What would be the best way of accomplishing this?

Flushing buffers in C

我与影子孤独终老i 提交于 2019-12-27 13:34:37
问题 Should fflush() not be used to flush a buffer even if it is an output stream? What is it useful for? How do we flush a buffer in general? 回答1: 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 crashing and I'm