unsafe

Unity3D Unsafe code requires the `unsafe' command line option to be specified

五迷三道 提交于 2019-12-05 06:21:04
i am using Unity3D 4.3 and calling a DLL that i created. when trying to call the only function it have which is this: void GetModelReferences(int &nVertices, float * vertices, int &nTriangles, int * triangles, float * normals, float * uvCoordinates); unity gives me an error: Unsafe code requires the `unsafe' command line option to be specified so in my MonoDevelop i opened : Project->Assembly-Csharp options and turned on the unsafe mode. it reduces part of the errors but this last one wont go away Unsafe code requires the `unsafe' command line option to be specified what shoud i do? Go to your

Should I mingle my safe code with my unsafe code?

China☆狼群 提交于 2019-12-05 04:31:19
I'm working on a project that uses a bunch of WIN32 API calls and requires some unsafe code. From a best practices standpoint should I isolate this code in its own DLL compiled with /unsafe switch while keeping my main application safe? To put it another way. Is there any reason not to compile a project with the /unsafe switch? Are there any potential risks? An assembly is by definition the smallest unit of independently versionable, redistributable code in .NET. Therefore the first question I would ask myself is "am I ever going to want to make a new version of the unsafe code and distribute

Why is my unsafe code block slower than my safe code?

六眼飞鱼酱① 提交于 2019-12-05 04:17:25
I am attempting to write some code that will expediently process video frames. I am receiving the frames as a System.Windows.Media.Imaging.WriteableBitmap . For testing purposes, I am just applying a simple threshold filter that will process a BGRA format image and assign each pixel to either be black or white based on the average of the BGR pixels. Here is my "Safe" version: public static void ApplyFilter(WriteableBitmap Bitmap, byte Threshold) { // Let's just make this work for this format if (Bitmap.Format != PixelFormats.Bgr24 && Bitmap.Format != PixelFormats.Bgr32) { return; } //

Fixed Size Array of Structure type

穿精又带淫゛_ 提交于 2019-12-05 02:48:32
how do I declare fixed-size array of a structure type in C# : [StructLayout(LayoutKind.Sequential,Pack=1), Serializable] public unsafe struct MyStruct{ ... } public class MyClass { ... public fixed MyStruct myStruct[256]; } this will result to CS1663 : fixed size buffers of struct type is not allowed, how do I workaround this ?, I prefer not to use C# or "Managed Collection data structure" type, as I need to frequently marshall this to native C++ If your C# struct uses only primitive data types and has exactly the same layout as your native struct in C++, you can get around these restrictions

Windows Phone 8(WP8) C# unsafe code?

我是研究僧i 提交于 2019-12-05 01:05:52
问题 EDIT: You can use unsafe code... you just have to manually edit the proj file. Why or why does C# on WP8 not support unsafe code when I can use native C++ code on the phone(I did not expect this)? I mean rly come on, I am so disappointed with what Microsoft is trying to force C# into. Is there any MS plans to support this in the future on WP8? I pass shader constants from C# to C++ and use unsafe code to optimize this process but on WP8 i'm going to be forced into doing this in some slow

Is mem::forget(mem::uninitialized()) defined behavior?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 00:37:31
In mutagen , I'm injecting various mutations in the code. One thing I'd like to mutate is the pattern if let Ok(x) = y { .. } . However, this poses quite the challenge, as I cannot know the type of y – the user could have built their own enum with an unary Ok variant. I can still opportunistically mutate it for cases where we actually have a Result whose error type implements Default using a trait that looks like the following simplified: #![feature(specialization)] pub trait Errorer { fn err(self, mutate: bool) -> Self; } impl<X> Errorer for X { default fn err(self, _mutate: bool) -> Self {

What are the implications of using unsafe code

ぃ、小莉子 提交于 2019-12-04 23:51:36
Aside from the fact that the code itself can access memory directly. What are the other implications of using the "/unsafe" compiler flag and the "fixed" keyword? Are there any knock on effects related to code signing and deployment of my .exe (my app is desktop only)? (This isn't about whether or not I should be doing this, the why is covered in my question here ) Unsafe code is not verifiable, so you have to be aware of that. In a Full Trust environment, that's not a big deal, but if you have other environments which have a more restricted permission set, then this might impact you there.

How to test handling of AccessViolationException

泄露秘密 提交于 2019-12-04 22:49:26
I need to write a test which verifies that my code can handle an AccessViolationException (or any other WIN32 Corrupted State Exception - CSE), which occours in an unsafe context, typically by calling a 3rd party lib. This should all be done using C# on .net 4.0. I found this related question How to handle AccessViolationException and this related article http://dotnetslackers.com/articles/net/All-about-Corrupted-State-Exceptions-in-NET4.aspx , which explains how to catch these CSE's and their background. So i would like to provoke a WIN32 CSE in a test, to ensure correct handling in my

LockBits Performance Critical Code

﹥>﹥吖頭↗ 提交于 2019-12-04 14:51:47
I have a method which needs to be as fast as it possibly can, it uses unsafe memory pointers and its my first foray into this type of coding so I know it can probably be faster. /// <summary> /// Copies bitmapdata from one bitmap to another at a specified point on the output bitmapdata /// </summary> /// <param name="sourcebtmpdata">The sourcebitmap must be smaller that the destbitmap</param> /// <param name="destbtmpdata"></param> /// <param name="point">The point on the destination bitmap to draw at</param> private static unsafe void CopyBitmapToDest(BitmapData sourcebtmpdata, BitmapData

How does Marshal.GetFunctionPointerForDelegate work on instance members?

五迷三道 提交于 2019-12-04 10:41:34
I am wondering about Marshal.GetFunctionPointerForDelegate. Namely I want to know how it converts a delegate to a function that is non static into a function pointer. Does it dynamically generate a code stub that has the instance attached somehow? And if so, doesn't this leak memory? Perhaps the delegate frees it in its finalizer? It doesn't look like System.Delegate has a finalizer, so I am very interested in how this mechanism works. I would assume that it would take 4 bytes for the function pointer and 4 bytes for the instance (on 32-bit), yet it returns a simple IntPtr. Big question,