Click here to Skip to main content
14,392,472 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 8:28
Memberhoney the codewitch19-Sep-19 8:28 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 8:35
Memberzezba900019-Sep-19 8:35 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 8:37
Memberhoney the codewitch19-Sep-19 8:37 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 8:43
Memberzezba900019-Sep-19 8:43 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 8:51
Memberhoney the codewitch19-Sep-19 8:51 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 9:01
Memberzezba900019-Sep-19 9:01 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 9:28
Memberhoney the codewitch19-Sep-19 9:28 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 9:37
Memberzezba900019-Sep-19 9:37 
No you don't have to copy memory if you use a native pointer to a memory mapped file.

In C# a pointer like "int*" is the same as a pointer in C/C++. There is no difference. That pointer in C# will directly be pointing to your native memory buffer you allocated from a native Win32 or POSIX API.

Pointers in C# can point to literally anything just as they can in C/C++. That includes managed and unmanaged memory locations.

For example this psuedo C# code would work:
[DllImport("nativeLib")]
static unsafe extern int* CreateNativeMemoryMappedFile();

unsafe void WriteMemoryMappedFile()
{
  int* nativeMemory = CreateNativeMemoryMappedFile();
  nativeMemory[0] = 123;// this is writing directly from the native buffer (not a copy)
  if (nativeMemory[1] == 321) return;// this is reading directly from the native buffer (not a copy)
}

GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 9:41
Memberhoney the codewitch19-Sep-19 9:41 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 10:05
Memberzezba900019-Sep-19 10:05 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 10:13
Memberhoney the codewitch19-Sep-19 10:13 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 10:18
Memberhoney the codewitch19-Sep-19 10:18 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 10:43
Memberzezba900019-Sep-19 10:43 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
honey the codewitch19-Sep-19 10:45
Memberhoney the codewitch19-Sep-19 10:45 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
zezba900019-Sep-19 10:47
Memberzezba900019-Sep-19 10:47 
GeneralRe: I thought .NET was supposed to make things easier, if anything, than unmanaged code. Pin
TheGreatAndPowerfulOz20-Sep-19 6:02
MemberTheGreatAndPowerfulOz20-Sep-19 6:02 
GeneralThought of the Day Pin
OriginalGriff18-Sep-19 5:45
mveOriginalGriff18-Sep-19 5:45 
GeneralRe: Thought of the Day Pin
W Balboos18-Sep-19 5:58
mveW Balboos18-Sep-19 5:58 
GeneralRe: Thought of the Day Pin
PeejayAdams18-Sep-19 6:16
MemberPeejayAdams18-Sep-19 6:16 
GeneralRe: Thought of the Day Pin
honey the codewitch18-Sep-19 6:19
Memberhoney the codewitch18-Sep-19 6:19 
GeneralRe: Thought of the Day Pin
lopatir18-Sep-19 6:26
Memberlopatir18-Sep-19 6:26 
GeneralRe: Thought of the Day Pin
honey the codewitch18-Sep-19 6:27
Memberhoney the codewitch18-Sep-19 6:27 
GeneralRe: Thought of the Day Pin
DRHuff18-Sep-19 7:22
MemberDRHuff18-Sep-19 7:22 
PraiseRe: Thought of the Day Pin
honey the codewitch18-Sep-19 7:23
Memberhoney the codewitch18-Sep-19 7:23 
GeneralRe: Thought of the Day Pin
PeejayAdams18-Sep-19 6:29
MemberPeejayAdams18-Sep-19 6:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.