unsafe

Can you limit the CPU usage on a .NET Process Object?

蹲街弑〆低调 提交于 2019-12-03 06:29:29
An application I'm contributing to fires up a component written in C. The C process does some pretty heavy crunching and if your not careful can really hammer your CPU. Is there a way to set a limit to external processes spawned by .NET? I've seen this artivcle on setting a hard memory limit at the OS level, is there a similar thing for CPU? Chris Shain Not in Windows. You can lower the process priority though, which will reduce the likelihood that the problematic process will be scheduled on the CPU and interfere with other (presumably higher priority) applications. For instance, from http:/

Why doesn't *(int*)0=0 cause an access violation?

谁都会走 提交于 2019-12-03 04:27:52
For educational purposes, I'm writing a set of methods that cause runtime exceptions in C# to understand what all the exceptions are and what causes them. Right now, I'm tinkering with programs that cause an AccessViolationException . The most obvious way (to me) to do this was to write to a protected memory location, like this: System.Runtime.InteropServices.Marshal.WriteInt32(IntPtr.Zero, 0); Just as I had hoped, this threw an AccessViolationException . I wanted to do it more concisely, so I decided to write a program with unsafe code, and do (what I thought was) exactly the same thing by

Why are JNI calls to native methods slower than similar methods in sun.misc.Unsafe?

穿精又带淫゛_ 提交于 2019-12-03 01:13:27
I'm developing a JNI implementation similar to sun.misc.Unsafe but with extended memory management. Why are the call times of native methods from sun.misc.Unsafe and from my developed library extremely different? Some numbers: sun.misc.Unsafe.getInt(address) takes ~1ns when my similar method takes ~10ns Both implementations are quite the same, following the source code of OpenJDK, just returning the variable by pointer. Both are registered in the same manner. How can I speed up JNI calls? What makes Unsafe performance so special? Thanks, Yury/ Peter Lawrey If you look for the source of the

Faster (unsafe) BinaryReader in .NET

送分小仙女□ 提交于 2019-12-02 17:33:59
I came across a situation where I have a pretty big file that I need to read binary data from. Consequently, I realized that the default BinaryReader implementation in .NET is pretty slow. Upon looking at it with .NET Reflector I came across this: public virtual int ReadInt32() { if (this.m_isMemoryStream) { MemoryStream stream = this.m_stream as MemoryStream; return stream.InternalReadInt32(); } this.FillBuffer(4); return (((this.m_buffer[0] | (this.m_buffer[1] << 8)) | (this.m_buffer[2] << 0x10)) | (this.m_buffer[3] << 0x18)); } Which strikes me as extremely inefficient, thinking at how

Bypassing C#'s type safeguards and storing an Integer in a String

可紊 提交于 2019-12-02 11:45:33
问题 Have a look at the following code: static void Main(string[] args) { string s = null; string[] myArray = new string[1]; { } // do something evil here if (s.GetType() == typeof(int)) { Console.WriteLine("This should not happen!"); } Console.ReadLine(); } Is there any way to get This should not happen to write? One would assume not. However, it can be done with the debugger: Put a breakpoint into the line { } // do something evil here and execute the following commands in the Immediate Window

How to use “unsafe” in JNI?

我只是一个虾纸丫 提交于 2019-12-02 09:51:22
Let's say I have a value pointed to by a (base,offset) tuple. e.g. class Data{ int x = 0; } class Accessor{ public Data data; public Object base$x; public long off$x; public static final Unsafe unsafe; public void run(){ data = new Data(); base$x = data; off$x = 12; unsafe.putInt(base$x,off$x,1); assert(data.x == 1); } static{ try { Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor(); unsafeConstructor.setAccessible(true); unsafe = unsafeConstructor.newInstance(); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException |

Convert pointer to loop option in C#

ⅰ亾dé卋堺 提交于 2019-12-02 06:54:42
How would I convert this into a loop and not to use the pointer. byte[] InputBuffer = new byte[8]; unsafe { fixed (byte* pInputBuffer = InputBuffer) { ((long*)pInputBuffer)[0] = value; } } I am trying to use the code from this page: query string parameter obfuscation There's no looping here. You could use BitConverter.GetBytes instead of the unsafe type-punning cast. byte[] InputBuffer = BitConverter.GetBytes(value); replaces all six original lines of code. 来源: https://stackoverflow.com/questions/4882378/convert-pointer-to-loop-option-in-c-sharp

Bypassing C#'s type safeguards and storing an Integer in a String

做~自己de王妃 提交于 2019-12-02 04:20:12
Have a look at the following code: static void Main(string[] args) { string s = null; string[] myArray = new string[1]; { } // do something evil here if (s.GetType() == typeof(int)) { Console.WriteLine("This should not happen!"); } Console.ReadLine(); } Is there any way to get This should not happen to write? One would assume not. However, it can be done with the debugger: Put a breakpoint into the line { } // do something evil here and execute the following commands in the Immediate Window before continuing: ((object[])myArray)[0] = 99; s = myArray[0]; Execution continues and This should not

Unsafe JavaScript attempt to access a frame when using secure browsing on Facebook

我的梦境 提交于 2019-12-02 00:44:08
I've launched an application last week and have noticed since that in Chrome only the height of my canvas is not always adjusted. I've spent a bunch of hours looking at the issues and noticed that I get the following error - sometimes. Unsafe JavaScript attempt to access frame with URL https://apps.facebook.com/tabletr/ from frame with URL http://static.ak.facebook.com/connect/canvas_proxy.php?version=3#behavior=p&method=getPageInfo&params=%7B%22channelUrl%22%3A%22https%3A%2F%2Fs-static.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D3%23cb%3Df3782154e%26origin%3Dhttps%253A%252F%252Ftabletr

angular2 and window.URL.createObjectURL

て烟熏妆下的殇ゞ 提交于 2019-12-01 18:09:22
问题 I use window.URL.createObjectURL to create a blob:http link for previewing selected image in an img tag: <img src=""{{itemPhoto}}"" /> itemPhoto is a field defined in a component and gets assigned when an image file is selected: selectPhoto(photos: any[]) { if (photos[0]) { this.itemPhoto = window.URL.createObjectURL(photos[0]); } } This works in angular2 RC1 but no longer works in 2.0.0. Here is what gets into the src attribute: unsafe:blob:http://localhost:5555/xxxxx-xxxx-xxxx-xxxx