unsafe Questions

3

Solved

I have a [u8; 16384] and a u16. How would I "temporarily transmute" the array so I can set the two u8s at once, the first to the least significant byte and the second to the most significant byte? ...
Imperfection asked 28/11, 2015 at 7:30

2

Solved

I have a massive vector that I want to be able to load/act on in parallel, e.g. load first hundred thousand indices in one thread, next in another and so on. As this is going to be a very hot part ...
Vtarj asked 27/7, 2015 at 2:33

1

Solved

I'm writing some unsafe Rust code so I need to know the exact differences between *const T and *mut T. I assumed that it's like &T and &mut T (i.e. you just can't mutate T through &T, p...
Cleveite asked 13/4, 2019 at 11:17

2

Solved

In unsafe code, is it correct to have several mutable references (not pointers) to the same array, as long as they are not used to write to the same indices? Context I would like to yield several...
Pockmark asked 11/2, 2019 at 15:7

1

Solved

I have complex number data filled into a Vec<f64> by an external C library (prefer not to change) in the form [i_0_real, i_0_imag, i_1_real, i_1_imag, ...] and it appears that this Vec<f64...
Karyotype asked 14/1, 2019 at 16:40

2

Solved

If I'm allocating memory with stackalloc in C#, is that memory initialized (with 0)? The documentation doesn't speak of that and only tells that the correct amount is reserved. In my tests such me...
Thyratron asked 30/12, 2011 at 11:37

7

Solved

Question I'm porting a C application into C#. The C app calls lots of functions from a 3rd-party DLL, so I wrote P/Invoke wrappers for these functions in C#. Some of these C functions allocate dat...
Grovel asked 9/7, 2013 at 13:14

1

Solved

This is taken out of context so it might seem a bit weird, but I have the following data structure: use std::marker::PhantomData; pub struct Map<T, M=()> { data: Vec<T>, _marker: Ph...
Ormiston asked 21/10, 2018 at 3:40

1

Solved

I have an array with [ManuallyDrop<Box<T>>] which is filled lazily. To realize this, I "initialize" the array with ManuallyDrop::new(mem::uninitialized()). Is this well-defined behavi...
Raeraeann asked 19/10, 2018 at 13:12

2

This did surprise me, I'm playing with Java Unsafe. Basically what I am testing is Allocate unsafe memory -> free the memory -> Write to the freed memory I was expecting to see some kind o...
Stultz asked 19/10, 2018 at 3:7

3

Solved

In this opencv example, the Mat object has a nativeObj field, returning a long that represents the address of the object (i.e 140398889556640). Because the size of the data within the object is kno...
Romine asked 3/10, 2018 at 9:55

1

Solved

I don't have a particularly solid understanding of Rust's aliasing rules (and from what I've heard they're not solidly defined), but I'm having trouble understanding what makes this code example in...
State asked 28/9, 2018 at 4:11

3

I would like to use new Span to send unmanaged data straight to the socket using SocketAsyncEventArgs but it seems that SocketAsyncEventArgs can only accept Memory<byte> which cannot be initi...
Dowel asked 6/9, 2018 at 18:53

1

Solved

I have noticed a certain behavior when using unsafe modifier at the class-level on partial classes that I was hoping to get some clarification on. I have been working on a rather large-wrapper, th...
Serialize asked 20/8, 2018 at 21:56

0

Summary I searched for an alternative for accessing private members with reflection and it seems I found one. The remaining questions are: Does it always work, regardless of the environment? Are...
Ealing asked 11/8, 2018 at 2:10

2

Solved

While studying the pointer through unsafe, I noticed something strange. unsafe class Program { static unsafe void Main(string[] args) { int A = 111; int B = 222; int* C = &A; Console....
Frederique asked 3/7, 2018 at 11:48

2

Solved

Background I wanted to make a few integer-sized structs (i.e. 32 and 64 bits) that are easily convertible to/from primitive unmanaged types of the same size (i.e. Int32 and UInt32 for 32-bit-sized...
Sepulture asked 15/6, 2018 at 7:27

2

Solved

msbuild doesn't seem to allow me build unsafe blocks even though my .csproj specify: <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> ... <AllowUnsafeBlock...
Balladmonger asked 17/8, 2016 at 9:7

2

Solved

I believe that an unsafe function is a function that says that it will return a value of some type, but that it can actually throw an exception and end the execution therefore not returning any val...
Bilk asked 27/9, 2015 at 2:40

1

Solved

A recent question was looking for the ability to construct self-referential structures. In discussing possible answers for the question, one potential answer involved using an UnsafeCell for interi...
Ximenez asked 20/5, 2018 at 4:36

1

Solved

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...
Armagnac asked 4/5, 2018 at 22:52

1

Solved

The following results don't make any sense to me. It looks like a negative offset is cast to unsigned before addition or subtraction are performed. double[] x = new double[1000]; int i = 1; // fo...
Lyallpur asked 26/3, 2018 at 18:22

1

Solved

I am trying to define a property that returns a pointer to a generic type argument like so: public class MemWrapper<T> where T: struct { readonly IntPtr pointerToUnmanagedHeapMem; // ... ...
Bybee asked 18/3, 2018 at 7:5

1

Solved

According to the C# reference for fixed statement: The fixed statement prevents the garbage collector from relocating a movable variable. ... After the code in the statement is executed, any pinne...
Stope asked 14/2, 2018 at 8:49

2

I am trying to understand the two methods here in java unsafe: public native short getShortVolatile(Object var1, long var2); vs public native short getShort(Object var1, long var2); What is...
Scute asked 5/2, 2018 at 3:23

© 2022 - 2024 — McMap. All rights reserved.