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
2 answers

Can I create a pointer to poll a float from any source?

Is there a way to access all the different types of object inherited from the same class using the same reference in an object without hard-coding it? I'm developing on unity and I want to add a module in my game that could watch any particular…
Léo Caussan
  • 29
  • 1
  • 6
0
votes
2 answers

C# Pointers to other application's memory

Possible Duplicate: How to access structure in other program's memory? Hello. I want to access another application memory. I'm writing game hack (Don't worry, it's only for single-player mode). I have found pointer to player structure in game's…
Hooch
  • 28,817
  • 29
  • 102
  • 161
0
votes
1 answer

Set double value to byte array in specific index

I programming in C#. I am looking for efficient way to set double (or any primitive) value into exist byte array in specific offset. I am familiar with BitConverter.GetBytes and the Buffer.BlockCopy command. I am looking for function that enable my…
MAK
  • 605
  • 9
  • 19
0
votes
1 answer

Why Unsafe.putOrderedObject is need in push of ForkJoinPool.WorkQueue instead of use array[index]

final void push(ForkJoinTask task) { ForkJoinTask[] a; ForkJoinPool p; int b = base, s = top, n; if ((a = array) != null) { // ignore if queue removed int m = a.length - 1; // fenced write for…
footmanff
  • 11
  • 3
0
votes
1 answer

How can i fill a byte array with a string without creating a new array?

I am trying to open multiple websockets and i need somehow to either use the same buffers per socket or clear them before sending/receiving new messages. The receive method is good since i can pass a parameter of byte array and it will fill that one…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
0
votes
3 answers

Is it safe to use a raw pointer to access the &T of a RefCell>?

I have a cache-like structure which internally uses a HashMap: impl Cache { fn insert(&mut self, k: u32, v: String) { self.map.insert(k, v); } fn borrow(&self, k: u32) -> Option<&String> { self.map.get(&k) …
Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
0
votes
2 answers

fputs vs fwrite in terms of safety

I am writing an application which has to find the sub string from a file and write this sub string into some different file. For writing into a file , I am using fputs, but someone told me to check the safer version for writing into the file. while…
ppandey
  • 311
  • 2
  • 3
  • 9
0
votes
1 answer

c# node struct circular dependency in custom LinkedListNode structure

So, I am trying to write a new linked list in c# that will behave properly in an unsafe context so I can pass it off to a multithreaded process. Unfortunately, even though all I need is a constant size pointer, this is creating a circular…
0
votes
0 answers

Where does the unsafe variable been set

When studying the jdk source code (jdk 1.8.0_111), i found a piece of strange code as follow: public class AtmicBoolean implements Serializable { private static final long serialVersionUID = 4654671469794556979L; private static final Unsafe…
Sampson
  • 9
  • 1
0
votes
1 answer

How to allow 'Unsafe code' in Rider for Mac version?

I don't know if I can turn on this option when using Rider 2017.2.1 (Mac version). Anyone could advise? I cannot find that option displayed at all. I googled: To configure properties of project build configurations In the Solution window,…
Huibin Zhang
  • 1,072
  • 1
  • 15
  • 30
0
votes
2 answers

C DLL does NOT Work in C# but Does work in C++

I don`t understand this code below, that it is working with my c++ but it just does not want to work with c#. Can you please help me to understand what is wrong here and i think i have to say that i am absolutely new to C#. My_Lib.h extern…
Abdurasul1996
  • 51
  • 1
  • 8
0
votes
1 answer

Is it still possible to use sun.misc.Unsafe in Java 9?

Until Java 8 it was possible to obtain the singleton sun.misc.Unsafe instance via a method like the following: public static Unsafe getUnsafe() { try { Field f = Unsafe.class.getDeclaredField("theUnsafe"); f.setAccessible(true); …
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
0
votes
0 answers

How to use "unsafe" in JNI?

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(){ …
User1291
  • 7,664
  • 8
  • 51
  • 108
0
votes
0 answers

Converting between equivalent Go maps

I was looking for a way to convert a map to another map, without copying key by key. Both maps have the equivalent key type (as demonstrated below). The code below seems to do the job, but I'm wondering what kind of pitfalls there might be if I use…
Kel
  • 1,217
  • 11
  • 21
0
votes
1 answer

Byte Pointer NullReferenceException

So, long story short, this is obviously valid code. Working in Unity3D- runs fine on PC. Build for Android- NRE when trying to access past the specific address pinned- NRE where commented in the code block below. public static unsafe byte[]…
user8245457