94 questions
3
votes
2
answers
210
views
what is the correct way to write byte array into unmanaged memory?
I faced a problem when I tried to write into virtual memory in C# program, I allocated the memory using VirtuAlloc function, and then write 10 bytes array into the memory using Marshal.Copy function, ...
0
votes
1
answer
235
views
.NET 8 delegate* unmanaged throws Fatal error
I try to call manually mapped AOT-compiled .NET dll.
When i create delegate to function pointer and call it, it throws exception "Fatal error. Invalid Program: attempted to call a ...
0
votes
2
answers
634
views
C# native memory usage
Is there a way to retrieve the total amount of native memory usage from a running C# application (either from within C# or an external CLI tool)? Something equivalent to the output of the non heap ...
0
votes
2
answers
3k
views
How to copy Span<byte> contents to location pointed by IntPtr?
I have an instance of Span<byte> which I would like to copy to unmanaged memory pointed by IntPtr. If I had a byte[], this would be an easy job, just call Marshal.Copy:
I know I can convert ...
0
votes
1
answer
1k
views
How to convert an IntPtr to array of structs
I have an IntPtr which is a pointer to an array of structs, and I'm trying to convert it to the array.
I tried
Marshal.Copy(srcIntPtr, destIntPtrArray, 0, destIntPtrArray.Length);
but after doing the ...
0
votes
1
answer
372
views
Mutable String in unmanaged memory useable in managed space
NOTE: My case is in the ecosystem of an old API that only work with Strings, no modern .NET additions.
So I have a strong need to have mutable string that has no allocations. String is updated every X ...
1
vote
1
answer
2k
views
How to locate unmanaged memory leak in c#
i am kind of stumped on a memory leak in our application. It only happens on the customers machines, or at least tests to reproduce it on my machine have failed. Luckily our application collects some ...
0
votes
1
answer
340
views
C# invoking unmanaged DLL: Bad_allocation exception thrown in DLL
I have been tasked to update a legacy 32-bit C# application to support converting 4K/UHD images (jpg, tiff, etc.) to an YUV image for further processing. The way we have accomplish converting SD/HD ...
0
votes
0
answers
179
views
How to check validity of a C pointer in C#?
An unmanaged pointer is passed to a method of a class in C#. Before manipulating, I need to make sure that the pointer is allocated with the claimed size and is still valid (not freed yet). How is it ...
1
vote
2
answers
7k
views
.net unmanaged memory leak
I have a windows service to receive emails that uses OpenPop. However memory usage goes up to 8G about 3 days after a restart. Operation staff gives me a dump file, So I use windbg to analysis it.
...
0
votes
1
answer
38
views
I cannot explain this diagram: "memory leak" or not?
I'm having issues trying to understand a memory usage diagram, hopefully someone more experienced in memory management will be able to tell if I'm facing a memory leak problem or not
To perform this ...
0
votes
0
answers
79
views
Use array of interface that return from a COM object
I have a COM dll (native) that I want to use it in my c# project, this dll has a function that get one IntPtr parameter like this :
int GetParameter(out paramCount,IntPtr paramInterfaceArray)
when I ...
0
votes
0
answers
39
views
return a generic reference from unmanaged memory
I have a generic class
class UnmanagedArray<T> where T: struct
{
IntPtr _backing; // unmanaged memory
// some constructors and others methods
// very slow but I don't care
...
17
votes
1
answer
5k
views
C# access unmanaged array using Memory<T> or ArraySegment<T>?
With the introduction of Memory, Span and ArraySegment in C# 7.2, I was wondering if I could represent an unmanaged array as an enumerable object, that lives on the heap.
This latter requirement ...
0
votes
1
answer
269
views
Marshal Unmanaged Unicode String in COM Task Allocator Memory to SecureString
I an working with API calls to advapi32.dll for managing Windows Saved Credentials in order to automate certain windows applications which can use saved credentials, which is working fine.
I am ...
1
vote
1
answer
281
views
Dispose inside a Parallel for is slower than a regular for loop. Why?
I have simplified my original issue into this test.
Using this class:
public class Unmanaged : IDisposable
{
private IntPtr unmanagedResource;
public Unmanaged()
{
this....
0
votes
1
answer
556
views
Exchange pinned array's pointer with an unmanaged memory pointer
I'm pinning and unpinning with:
GCHandle pinArray(object a)
{
return GCHandle.Alloc(a, GCHandleType.Pinned);
}
void unpinArray(GCHandle h)
{
h.Free();
}
...
6
votes
1
answer
1k
views
F# NativePtr.stackalloc slower then C# stackalloc - Decompiled Code Included
Continuing my F# performance testing. For some more background see here:
f# NativePtr.stackalloc in Struct Constructor
F# NativePtr.stackalloc Unexpected Stack Overflow
Now I've got stack arrays ...
3
votes
1
answer
385
views
f# NativePtr.stackalloc in Struct Constructor
I'm doing some F# performance testing and am trying to create an array on the stack rather then the heap (value vs reference type). I am using NativePtr.stackalloc to allocate memory on the stack. ...
0
votes
0
answers
254
views
Free IntPtr to IntPtr
I have class called Parent :
Class Parent
{
String Name;
IntPtr Childs; // this pointer actual type is 'Array of Child' and it was storred as unmanned array
int ChildsCount;// count of '...
1
vote
0
answers
161
views
Why does fragmentation of the managed heap affect the success of unmanaged heap allocation requests?
I have not been able to find a satisfactory explanation as to why calling GC.Collect before a large unmanaged allocation (in my case, before creating a large (~250Mb) DirectX resource) prevents an out-...
1
vote
2
answers
1k
views
Trouble with passing handle to managed object using PInvoke
I'm quite confused about how to pass handle to my managed object from .Net to unmanaged code. Now I'm developing kind of "driver" for Oracle Siebel CRM using C#. And how i faced with problem about how ...
1
vote
0
answers
72
views
Can I pass a locked .NET BitmapData.Scan0 to unmanaged C++? [duplicate]
I wanted to know whether sending a locked Bitmap's BitmapData.Scan0 field to unmanaged C++ could be an issue. Here's how I do it:
From C#.NET:
public class BmpTest{
Bitmap bmp = new Bitmap();
...
0
votes
1
answer
324
views
Utilizing c++ from c#
I currently have some c++ code which processes 'char ***myArray' much faster than any other method for string comparison.
I'm also wrapping my c++ into a DLL and calling functions from a C# GUI which ...
3
votes
1
answer
2k
views
Marshal.StructureToPtr without boxing
Is there a way to marshal a structure (possibly stored in a TypedReference) to unmanaged memory without actually boxing it? The type of the structure isn't known at runtime, so I can't use the generic ...