unsafe

Unsafe C# - Instantiate Pointer at lowest memory address and overwrite

Is it possible to instantiate a pointer using (unsafe) C# at any given memory address (which one would be the lowest?) and simply start overwriting the memory with continuous random data until a PC crashes? Could someone provide me with an example? ...

Function C++ to C# (safe code)

Hi, i need help. c++: static void doIp(byte data[]) { unsigned char j, k; byte val; byte buf[8]; byte *p; byte i = 8; for(i=0; i<8; i++) { val = data[i]; p = &buf[3]; j = 4; do { for(k=0; k<=4; k+=4) { p[k] >>= 1; if(val & 1) p[k] |= 0x80; val >>= 1; } ...

unsafe c# code causes heap corruption on 64 bit platform unless built for x86 platform.......

Hi all, I have a simple util that uses some unsafe code to get the file version information. when I compiled this as mixed platform (vs2008/.net 3.5) and deploy to 64 bit machine I get a heap corruption error. If I recompile as x86 then everything works.... This was suprising because of my understanding of the .NET Common Type Syste...

Should I use pointers in a MMORPG emulator?

Hello, I have a MMORPG emulator, this means it will be handling packets quite a bit. Currently, I am using pointers for this, as I think when used correctly, they can speed up my server, however I've got two friends, one is telling me to use pointers, he thinks I can use them without running into trouble, my other friends says I should n...

Initialize a collection of byte* in C#

My unsafe method accepts a collection byte[]s. All of these byte[]s are of the same size. I need to iterate over them all, searching for certain patterns. The search is inherently reinterpret-cast style: at each offset, I need to consider a value as if it were a float, a double, a short, an int, etc. So getting a byte* for each input by...

Converting System.Decimal to System.Guid

I have a big dictionary where the key is decimal, but the GetHashCode() of System.Decimal is disasterously bad. To prove my guess, I ran a for loop with 100.000 neigboring decimals and checked the distribution. 100.000 different decimal numbers used only 2 (two!!!) different hashcodes. Decimal is represented as 16 bytes. Just like Guid!...

How to use different credentials with several COM objects (via RCW) in .NET

My understanding is that as soon as .NET fires up the RCW to access a COM object, the security credentials are persisted within the COM context until the .NET application is closed... thereby preventing the use of different credentials later on during execution. There is a RCW wrapper on Codeplex that I think will allow me to take a giv...

Perl Threads and Unsafe Signals

So I recently wanted to thread one of my Perl programs to increase its speed. Taking in a list of websites, I wanted to start a thread for each url and get the content of each website and then look for a company description on the page. Once one thread found a result, or all thread's didn't, I wanted to exit, write my result, and read ...

Re-interpreting a byte array as an array of structs

I've got a byte array that I want to re-interpret as an array of blittable structs, ideally without copying. Using unsafe code is fine. I know the number of bytes, and the number of structs that I want to get out at the end. public struct MyStruct { public uint val1; public uint val2; // yadda yadda yadda.... } byte[] stru...

Deploying unsafe code in Azure cloud

Has anyone tried deploying unsafe code in Azure? I'm working with code containing unsafe blocks dealing with pointers and all that fun stuff. And I'm wondering if that has something to do with errors I'm getting trying to deploy/upgrade the web project in Azure. Also, is there actually a way to view specific errors that are breaking...

Calling unsafe code from managed (C#). Reading byte array.

Hello everyone, I have this method that I need to call and use in my application, but I don't know really know how to do it exactly. This is the function that I need to call. [DllImport(dll_Path)] public static extern int DTS_GetDataToBuffer(int Position, int Length, char* Buffer, int* DataRead); In my code, I have this function and...

C#: Maximum length of byte[]?

I'm trying to create an array of bytes whose length is UInt32.MaxValue. This array is essentially a small(ish) in-memory database: byte[] countryCodes = new byte[UInt32.MaxValue]; On my machine, however, at run-time, I get a System.OverflowException with "Arithmetic operation resulted in an overflow". What's the deal? Do I need to us...

Is there a speed benefit to using unsafe code in .Net to swap objects of complex types?

Here is my current swap code for swapping 2 KeyValuePair objects in an array: KeyValuePair<int, T> t = a[i]; a[i] = a[j]; a[j] = t; Would there be any speed advantage to using unsafe code and merely swapping the pointers of the 2 objects? Or does the complier effectively boil this safe code down to effectively ...

constant-time set operations

Are there constant-time algorithms for binary set intersection and union? I imagine using bitmaps with pointers to elements in the memory and using OR for union and AND for intersection. Does anyone now of a solution? ...