buffer

Java: FloatBuffer to OpenGL - wrap() vs. allocate() vs. BufferUtils.createBuffer()

佐手、 提交于 2019-12-20 03:10:44
问题 Datasource: float[] v = { ... }; Working example: FloatBuffer buf = BufferUtils.createFloatBuffer(v.length); buf.put(v); buf.flip(); // or buf.rewind() The buffer can now be uploaded to opengl and works fine: ... glBufferData(..., buf, ...); ... Why do the following examples of the buffer creation not also work? Not working 1: FloatBuffer buf = FloatBuffer.wrap(v); Not working 2: FloatBuffer buf = FloatBuffer.allocate(v.length); buf.put(v); buf.flip(); // or buf.rewind() Edit: After browsing

Python writing binary files, bytes

落花浮王杯 提交于 2019-12-19 16:35:56
问题 Python 3. I'm using QT's file dialog widget to save PDFs downloaded from the internet. I've been reading the file using 'open', and attempting to write it using the file dialog widget. However, I've been running into a"TypeError: '_io.BufferedReader' does not support the buffer interface" error. Example code: with open('file_to_read.pdf', 'rb') as f1: with open('file_to_save.pdf', 'wb') as f2: f2.write(f1) This logic works properly with text files when not using the 'b' designator, or when

How does BufferedOutputStream actually work at a low level?

若如初见. 提交于 2019-12-19 07:54:16
问题 I understand the theory behind BufferedOutputStream . Bytes are written to a buffer array until it is full, and then written (flushed) to the underlying stream - the idea being that it is faster than writing byte-by-byte as there are fewer OS calls. However, from looking at the implementation of the BufferedOutputStream class and methods (BufferedOutputStream.java), it seems that ultimately, the bytes from the buffer are just written byte-by-byte. I think this is the case because: In

Emacs: Switching Between Buffers with the Same Name but in Different Directories

夙愿已清 提交于 2019-12-19 06:57:53
问题 I have two files with the same name but in different directories: apples/main.cpp oranges/main.cpp I open them in one emacs window via emacs apples/main.cpp oranges/main.cpp When I use C-x b to switch between these two buffers, the buffer names are "main.cpp" and "main.cpp<2>". I would love to be able to see the full path of these two files when switching buffers, so that I may disambiguate between the apples and the oranges version. Is there a way to do this? One way could be to modify

What is the optimal StringBuffer initial capacity for inputs with drastically varying lengths?

江枫思渺然 提交于 2019-12-19 06:56:51
问题 Good afternoon all, I'm using a java.lang.StringBuilder to store some characters. I have no idea how many characters I'm going to store in advance, except that: 60% of the time, it is only (exactly) 7 characters 39% of the time, it is (roughly) 3500 characters 1% of the time, it is roughly 20k characters How do we go about calculating the optimal initial buffer length that should be used? Currently I'm using new java.lang.StringBuilder(4000) but that's just because I was too lazy to think

Causing a buffer Overflow with fgets

≯℡__Kan透↙ 提交于 2019-12-19 05:24:11
问题 I'm experimenting with buffer overflows and try to overwrite the return address of the stack with a certain input of fgets This is the code: void foo() { fprintf(stderr, "You did it.\n"); } void bar() { char buf[20]; puts("Input:"); fgets(buf, 24, stdin); printf("Your input:.\n", strlen(buf)); } int main(int argc, char **argv) { bar(); return 0; } On a normal execution the program just returns your input. I want it to output foo() without modifying the code. My idea was to overflow the buffer

Force flush to Observable.Buffer c#

爷,独闯天下 提交于 2019-12-19 03:43:08
问题 Is there any way to force a Observable.Buffer to flush before the end of buffered time? In the example: mSubscription = mFluxObservable.Buffer(new TimeSpan(0, 0, 1, 30)).Subscribe(o => saver(o, iSessionId)); I want to flush the data before the 1:30 period has finished! 回答1: This worked for me: var subject = new Subject<Unit>(); var closing = Observable .Timer(new TimeSpan(0, 0, 1, 30)) .Select(x => Unit.Default); var query = mFluxObservable .Buffer(() => Observable .Amb(subject, closing)

Buffer growth strategy

对着背影说爱祢 提交于 2019-12-18 14:52:02
问题 I have a generic growing buffer indended to accumulate "random" string pieces and then fetch the result. Code to handle that buffer is written in plain C. Pseudocode API: void write(buffer_t * buf, const unsigned char * bytes, size_t len);/* appends */ const unsigned char * buffer(buffer_t * buf);/* returns accumulated data */ I'm thinking about the growth strategy I should pick for that buffer. I do not know if my users would prefer memory or speed — or what would be the nature of user's

Make ipython notebook print in real time

末鹿安然 提交于 2019-12-18 14:05:44
问题 Ipython Notebook doesn't seem to print results in real time, but seems to buffer in a certain way and then bulk output the prints. How can I make ipython print my results as soon as the print command is processed? Example code: import time def printer(): for i in range(100): time.sleep(5) print i Supposing that the above code is in a file that is imported. How could I make it that when I call the printer function it prints a number every 5 seconds and not all the numbers at the very end?

How can I set the buffer size for the underneath Socket UDP? C#

∥☆過路亽.° 提交于 2019-12-18 13:19:20
问题 As we know for UDP receive, we use Socket.ReceiveFrom or UdpClient.receive Socket.ReceiveFrom accept a byte array from you to put the udp data in. UdpClient.receive returns directly a byte array where the data is My question is that How to set the buffer size inside Socket. I think the OS maintains its own buffer for receive UDP data, right? for e.g., if a udp packet is sent to my machine, the OS will put it to a buffer and wait us to Socket.ReceiveFrom or UdpClient.receive, right? How can I