|
I'm pretty sure I'd need to cross compile the C code as Virtual memory management is completely different under windows than it is in linux for example. I don't think i can even map arbitrary files to process address space in linux but i could be wrong.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
You would have to cross-compile if you go the route of compiling a separate library (in, let's say, C) for this stuff. But you can also go with P/Invoke which you "cross compile" via runtime checks. .NET Core supports this scenario, I haven't checked on Mono (yet). https://stackoverflow.com/questions/38790802/determine-operating-system-in-net-core
|
|
|
|
|
yeah in the general sense, but in this case, i'd need two binaries per platform (one managed, one unmanaged) probably. #ifs require compilation of course, in C# as well as C
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Why do you insist on an unmanaged binary? Why don't you want to do your unmanaged ABI calls with P/Invoke?
|
|
|
|
|
Because it's impossible to map a file to process address space in C#.
You can only marshal calls to the vmem system which makes it exactly like reading and writing a file instead of reading and writing a pointer. Defeating the primary reason I'd use it.
what I want (and can't have)
var foo = new int[100000];
and i don't want an unmanaged binary. I'm speaking in the hypothetical. I will not use vmem in this project because of .NET limitations.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Write an "array" class which looks like an array from the outside but works with ABI calls internally. Using container classes is often recommended over using plain arrays in C# anyway.
|
|
|
|
|
it has been done. It's called List<t>/IList<t> and it doesn't help me. It does zero to reduce the complexity of what I'm trying to do.
I don't actually need an int array. I need a B+tree. Try wrapping that in something fun and you'll have done my job.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
http://csharptest.net/projects/bplustree
From the description "BPlusTree is a implementation of the generic IDictionary<TKey, TValue> interface backed by a disk-based B+Tree".
|
|
|
|
|
yeah i've seen that. it's cool. thread safe too as i recall. I'd rather build one. Using that won't teach me anything
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Then go ahead. Build an own class which runs on platform ABI calls internally guarded by runtime platform checks and implements the interface you want. It's a PITA, that I absolutely agree with but on the other hand, the greater the learning effect and if there's a clean interface, the implementation doesn't matter anyway (except for said learning effect).
|
|
|
|
|
I'm probably going to write it all in managed code.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Exactly my point, keep it managed, save yourself the trouble of cross-compiling and furthermore, the distributional pain. Distributing different binaries for different platforms has been the norm for pretty much forever (in computing at least), but .NET Core/Mono provide means to do it better. Hey, remember when even DOS software had to have different binaries for different computer vendors despite them all running DOS? I surely don't miss those days.
|
|
|
|
|
I planned to keep it managed from the beginning. The only reason i discussed an unmanaged scenario is because memory mapped files basically don't work - at least how they were designed to be used - under .NET.
I wanted people to understand the problem domain. I do not make mixed mode distributions anymore.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I don't quite believe you that memory-mapped files don't work in .NET since .NET has a MemoryMappedFile class.
|
|
|
|
|
I said they don't work how they are supposed to.
How they were designed was to map files to a process address space so you could do pointer ops to read and write files.
That is not doable under .NET.
Sorry I've just explained this a lot. If you've used memory mapped files in unmanaged code then you know what i'm talking about. Otherwise you might never. I don't know.
You cannot do
var foo = new int[100000]; //backed by file.
That's how it's supposed to work. It can't under .NET
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: It can't under .NET
not even with "unsafe"?
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
This StackOverflow question appears to allow you to get a fixed pointer to a mapped view. Then you could use a Span object to provide an array representation over that memory range (use the constructor that takes a Void* and Int32 ) and then writes to the Span would be written to the mapped memory and thus to the mapped file?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Oooh now that's clever.I forgot about span! Hmmm. this might be doable. thanks for the link.
Span is cool.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
No problem...
Inspiration came from using std::slice in Rust and gsl::span in C++ - both create a non-owning array-like wrapper over a chunk of memory...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
yeah. My professional dev years are behind me and so the newer .NET stuff I'm still picking up. I even stopped coding for years.
But I remember span, now that you mention it of course. I thought it was one of the coolest new features of .NET =)
Now if i can just remember it all the time.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I believe this is the type of library you are looking for...
C# BPlusTree
Steve Naidamast
Sr. Software Engineer
Black Falcon Software, Inc.
blackfalconsoftware@outlook.com
|
|
|
|
|
I've seen that. This is a learning exercise for me, so I'm not looking for one that's already made.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Use unsafe code with pointers just as you would in C and you can do the same thing as you could in C.
|
|
|
|
|
Nope, because you can't pin an object to a specific address in memory.
Ergo I can't back a .NET instance with a memory mapped file.
Memory mapped files work by mapping a portion of the process address space to your application.
So you can read and write the file doing pointer ops.
However, in .NET you can only get pointers to the GC heap by pinning objects.
So I cannot do
var arr = new int[100000000];
in any variation. Even if I were to pin the array to get the pointer, the pointer wouldn't be part of that mapped address space.
At best, I have to *copy* the entire object into that mapped region, which absolutely defeats the whole point of why I'd use mem mapped I/O here in the first place.
There's a half measure using Span, but it only works in Standard and Core, not the DNF
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|