Questions tagged [unsafe]

In C# or Rust, the unsafe keyword marks code able to work directly with memory pointers, bypassing some of the language's safety checks. In Java, `sun.misc.Unsafe` is a special class performing low-level, unsafe operations.

In C# The unsafe keyword denotes an unsafe context, which is required for any operation involving pointers. You can use the unsafe modifier in the declaration of a type or a member. Once so declared, the entire textual extent of the type or member is considered an unsafe context.

For more information, see Unsafe Code and Pointers (C# Programming Guide)

The unsafe Keyword on MSDN
http://msdn.microsoft.com/en-us/library/chfa2zb8(v=vs.100).aspx


In Java, sun.misc.Unsafe is a special class performing low-level, unsafe operations. Though this is a private platform API, this class is used extensively in many projects and libraries including Hadoop, Spark, Guava, Cassandra, etc.


In Rust, the unsafe keyword denotes a function or block that is implemented outside some of the safeguards of the compiler. Thus it is as much an escape hatch as a device to easily document code that might require increased attention. More information can be found in the Rust Book


In Go, package unsafe contains operations that step around the type safety of Go programs. Packages that import unsafe may be non-portable and are not protected by the Go 1 compatibility guidelines.

990 questions
0
votes
0 answers

Is it possible to access unmanaged and managed array elements indiscriminately?

An example will make this clear: unsafe void ProcessUnmanagedBuffer( float * buffer, int length ) { int i; for( i = 0; i < length; i++ ) { buffer[ i ] = ...; } } void ProcessManagedBuffer( float[] buffer, int length ) { …
Gregzo
  • 1,194
  • 7
  • 18
0
votes
3 answers

How do I change the address of a New struct in a loop?

I'm writing a simple program which is about polynomials using linked lists in C#. The problem I have is that whenever it creates a new struct (node) in the for loop it gives it the same address as the previous node was given. How do I fix that? …
Yasin
  • 609
  • 1
  • 10
  • 22
0
votes
1 answer

Is it safe to use the hash of the plain text as a key for encryption?

If encrypt the plain text with its hash is it correct?? Where Can I find a paper that speak about it? Is it possible Known-plaintext attack?
pass92
  • 1
  • 1
0
votes
1 answer

"unsafe code may only appear if compiling with /unsafe"

I have a web application and in one of the classes the following is defined (partial): public class DllFunction { [DllImport("CARSDBI.dll", EntryPoint="CARSDBI_EnableLogging")] public static extern unsafe void CARSDBI_EnableLogging(int…
NoBullMan
  • 2,032
  • 5
  • 40
  • 93
0
votes
1 answer

How can I speed this routine up?

I have the following code that needs to run at 25fps or better which we can at the moment. Eventually we will be using HD video so this will need to be optimized more to accomodate. Is there any way I can optimize this method? public unsafe void…
Simon
  • 9,197
  • 13
  • 72
  • 115
0
votes
1 answer

Google fonts triggering "Unsafe script" in chrome

When I am using Google Fonts in an HTTPS page it is treated like an "unsafe script" in chrome. Any workarounds?
Slava Knyazev
  • 5,377
  • 1
  • 22
  • 43
0
votes
0 answers

How to make all my site scripts safe for browsers?

Okay, so i have this problem, i tried searching it on google, had no luck. When a browser loads my site, it says that there are unsafe scripts there, but all the scripts are working properly except google fonts. To make them work i have to click…
Jockey
  • 75
  • 1
  • 1
  • 5
0
votes
1 answer

Write transparency to bitmap using unsafe with the original colors preserved?

In this code I'm creating Transparent bitmap but coloring the pixels in the List testpoints in yellow. How can I keep make it Transparent but the pixels to be coloring or keep with the original colors of them instead yellow ? private void…
James Aharon
  • 223
  • 1
  • 4
  • 13
0
votes
1 answer

.java uses unchecked and unsafe operation

here is my java code: import javax.swing.*; public class Employee1 extends JFrame { JPanel panel; JLabel l1; JList list; public Employee1() { super("Employee Details"); panel = new JPanel(); l1 = new…
vbhvbhurke
  • 3
  • 1
  • 3
0
votes
1 answer

Bitmap Scan0, Stride off

I'm writing a program that apply xored delta's to a existing bitmap. The problem i'm having is it seems to be 5 pixles off in the first iteration leading too some interesting color effects private void ApplyDelta(ref Bitmap bitmapA, Bitmap bitmapB,…
KevinA
  • 619
  • 6
  • 25
0
votes
1 answer

C#. How to pass message from unsafe callback to managed code?

Is there a simple example of how to pass messages from unsafe callback to managed code? I have a proprietary dll which receives some messages packed in structs and all is coming to a callback function. The example of usage is as follows but it calls…
please delete me
0
votes
1 answer

Copy Small Bitmaps on to Large Bitmap with Transparency Blend: What is faster than graphics.DrawImage(smallBitmap, x , y)?

I have identified this call as a bottleneck in a high pressure function. graphics.DrawImage(smallBitmap, x , y); Is there a faster way to blend small semi transparent bitmaps into a larger semi transparent one? Example Usage: XY[] locations =…
Glenn
  • 1,234
  • 2
  • 19
  • 33
0
votes
3 answers

Operator '&' cannot be applied to operands of type 'ulong' and 'ulong*'

Operator '&' cannot be applied to operands of type 'ulong' and 'ulong*' What am I doing wrong? I'm trying to find which masks a integer consists of, if that makes sense. e.g. 63 = 1+2+4+8+16+32 unsafe { UInt64 n =…
user3685954
  • 35
  • 1
  • 7
0
votes
1 answer

How to use GetBufferSubData?

I am currently playing around with SharpGL but can not figure out how to use it's function GetBufferSubData in proper way. public void GetBufferSubData(uint target, int offset, …
frankie
  • 728
  • 1
  • 10
  • 28
0
votes
1 answer

B tree unsafe vs safe variant in c#

Today I get a task to realise B tree and I am interesting whether unsafe code with fixed buffers will be more effective for working with disk? As we will work with whole segments but not with disparate segments of memory (as would be when we work…