Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I thought .NET was supposed to make things easier, if anything, than unmanaged code.

I thought .NET was supposed to make things easier, if anything, than unmanaged code.

Scheduled Pinned Locked Moved The Lounge
csharpdatabasesql-servercomsysadmin
111 Posts 19 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H honey the codewitch

    Yes, though it was added to .NET after my initial attempt at using mem mapped files from C#. Besides all that is is a wrapper like the one i had written years ago. It doesn't change the basic problem which is: var foo = new int[1000000]; //backed by disk, paged automatically, in C/C++ it's mainly because you can't use pointers in C#, and even if you use unsafe, you cannot pin objects to specific addresses in memory

    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.

    J Offline
    J Offline
    johannesnestler
    wrote on last edited by
    #43

    So you can't pin?: whatabout [fixed Statement - C# Reference | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement) So I think it's time to use the latest .NET Version and have a look into what has changed...

    H 1 Reply Last reply
    0
    • J johannesnestler

      So you can't pin?: whatabout [fixed Statement - C# Reference | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/fixed-statement) So I think it's time to use the latest .NET Version and have a look into what has changed...

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #44

      pinning does not solve this problem. I don't need a random pointer .NET produced from the GC heap. The only thing i could do with that is throw it away. It's useless for this

      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.

      1 Reply Last reply
      0
      • R Rajesh R Subramanian

        I'm not sure why you feel the need to tell me that you worked at Microsoft. If you were trying to imply that it adds credibility to what you say, I've go to tell you that I've met some real nimrods who came from Microsoft to those MVP summits I used to go to. I'm sure that a number of exceptionally talented people work or have worked at Microsoft, but there are also these nimrods (who thought they were exceptionally talented). A random sample could belong to either camp. Because you had to say that, I had to say this.

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #45

        No I'm telling you i don't need your lectures about the very basics of how .NET works. I don't care if you find me credible because your opinion doesn't matter to me. If that were to change, we'll talk.

        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.

        R 1 Reply Last reply
        0
        • M Member 9167057

          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.

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #46

          it has been done. It's called List/IList 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.

          M 1 Reply Last reply
          0
          • H honey the codewitch

            it has been done. It's called List/IList 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.

            M Offline
            M Offline
            Member 9167057
            wrote on last edited by
            #47

            http://csharptest.net/projects/bplustree From the description "BPlusTree is a implementation of the generic IDictionary interface backed by a disk-based B+Tree".

            H 1 Reply Last reply
            0
            • M Member 9167057

              http://csharptest.net/projects/bplustree From the description "BPlusTree is a implementation of the generic IDictionary interface backed by a disk-based B+Tree".

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #48

              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.

              M 1 Reply Last reply
              0
              • H honey the codewitch

                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.

                M Offline
                M Offline
                Member 9167057
                wrote on last edited by
                #49

                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).

                H 1 Reply Last reply
                0
                • M Member 9167057

                  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).

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #50

                  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.

                  M 1 Reply Last reply
                  0
                  • H honey the codewitch

                    No I'm telling you i don't need your lectures about the very basics of how .NET works. I don't care if you find me credible because your opinion doesn't matter to me. If that were to change, we'll talk.

                    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.

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #51

                    honey the codewitch wrote:

                    No I'm telling you i don't need your lectures about the very basics of how .NET works.

                    I responded to you with a couple of one liners, and you term those as "lectures"?

                    honey the codewitch wrote:

                    I don't care if you find me credible

                    That's probably why you tried desperately to establish that you're sooo good with announcing your "Microsoft backgroundz"? Geez, try and make some sense occasionally.

                    honey the codewitch wrote:

                    your opinion doesn't matter to me.

                    Ha, we finally have something in common.

                    honey the codewitch wrote:

                    If that were to change, we'll talk.

                    No, thank you. X| :thumbsdown:

                    H 1 Reply Last reply
                    0
                    • H honey the codewitch

                      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.

                      M Offline
                      M Offline
                      Member 9167057
                      wrote on last edited by
                      #52

                      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.

                      H 1 Reply Last reply
                      0
                      • R Rajesh R Subramanian

                        honey the codewitch wrote:

                        No I'm telling you i don't need your lectures about the very basics of how .NET works.

                        I responded to you with a couple of one liners, and you term those as "lectures"?

                        honey the codewitch wrote:

                        I don't care if you find me credible

                        That's probably why you tried desperately to establish that you're sooo good with announcing your "Microsoft backgroundz"? Geez, try and make some sense occasionally.

                        honey the codewitch wrote:

                        your opinion doesn't matter to me.

                        Ha, we finally have something in common.

                        honey the codewitch wrote:

                        If that were to change, we'll talk.

                        No, thank you. X| :thumbsdown:

                        H Offline
                        H Offline
                        honey the codewitch
                        wrote on last edited by
                        #53

                        Rajesh R Subramanian wrote:

                        No, thank you.

                        Nobody made you respond to me. Now I'm not listening to this anymore. Have good day.

                        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.

                        R 1 Reply Last reply
                        0
                        • H honey the codewitch

                          Rajesh R Subramanian wrote:

                          No, thank you.

                          Nobody made you respond to me. Now I'm not listening to this anymore. Have good day.

                          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.

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #54

                          honey the codewitch wrote:

                          Nobody made you respond to me.

                          If you're a nobody, then yes.

                          honey the codewitch wrote:

                          Now I'm blocking you so I don't have to listen to this anymore.

                          TMI - I don't need to know what you are doing on the internet.

                          T 1 Reply Last reply
                          0
                          • M Member 9167057

                            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.

                            H Offline
                            H Offline
                            honey the codewitch
                            wrote on last edited by
                            #55

                            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.

                            M 1 Reply Last reply
                            0
                            • H honey the codewitch

                              I know this is a very special case but still i ran headlong into it. The easiest way to implement a B+ tree on disk is using a memory mapped file. I think this is what SQL Server does, but don't quote me. However, the only way you can access memory mapped files in C# is through .NET interop which makes it useless. Because one of the points of a memory mapped file is that you can do memory allocations that are backed by disk. There's no way in hell .NET can give you that in its current incarnation, even if one were to write a custom host, because of the way a GC system works. What I'd like var foo = new int[1000000]; // backed by disk, paged automatically What I'd have to do. somepointer = VirtualAlloc(...) Write(somepointer, data) etc etc basically it works like file i/o which defeats essentially the whole purpose. =(

                              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.

                              S Offline
                              S Offline
                              Stuart Dootson
                              wrote on last edited by
                              #56

                              [This StackOverflow question](https://stackoverflow.com/questions/31179076/how-to-get-an-intptr-to-access-the-view-of-a-memorymappedfile) 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`](https://docs.microsoft.com/en-us/dotnet/api/system.span-1.-ctor?view=netstandard-2.1#System\_Span\_1\_\_ctor\_System\_Void\_\_System\_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

                              H 1 Reply Last reply
                              0
                              • S Stuart Dootson

                                [This StackOverflow question](https://stackoverflow.com/questions/31179076/how-to-get-an-intptr-to-access-the-view-of-a-memorymappedfile) 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`](https://docs.microsoft.com/en-us/dotnet/api/system.span-1.-ctor?view=netstandard-2.1#System\_Span\_1\_\_ctor\_System\_Void\_\_System\_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

                                H Offline
                                H Offline
                                honey the codewitch
                                wrote on last edited by
                                #57

                                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.

                                S 1 Reply Last reply
                                0
                                • H honey the codewitch

                                  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.

                                  M Offline
                                  M Offline
                                  Member 9167057
                                  wrote on last edited by
                                  #58

                                  I don't quite believe you that memory-mapped files don't work in .NET since .NET has a MemoryMappedFile class.

                                  H 1 Reply Last reply
                                  0
                                  • M Member 9167057

                                    I don't quite believe you that memory-mapped files don't work in .NET since .NET has a MemoryMappedFile class.

                                    H Offline
                                    H Offline
                                    honey the codewitch
                                    wrote on last edited by
                                    #59

                                    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.

                                    T 1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      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.

                                      S Offline
                                      S Offline
                                      Stuart Dootson
                                      wrote on last edited by
                                      #60

                                      No problem... Inspiration came from using [std::slice](https://doc.rust-lang.org/std/slice/fn.from\_raw\_parts.html) in Rust and [gsl::span](http://codexpert.ro/blog/2016/03/07/guidelines-support-library-review-spant/) 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

                                      H 1 Reply Last reply
                                      0
                                      • S Stuart Dootson

                                        No problem... Inspiration came from using [std::slice](https://doc.rust-lang.org/std/slice/fn.from\_raw\_parts.html) in Rust and [gsl::span](http://codexpert.ro/blog/2016/03/07/guidelines-support-library-review-spant/) 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

                                        H Offline
                                        H Offline
                                        honey the codewitch
                                        wrote on last edited by
                                        #61

                                        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.

                                        1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          Yes, though it was added to .NET after my initial attempt at using mem mapped files from C#. Besides all that is is a wrapper like the one i had written years ago. It doesn't change the basic problem which is: var foo = new int[1000000]; //backed by disk, paged automatically, in C/C++ it's mainly because you can't use pointers in C#, and even if you use unsafe, you cannot pin objects to specific addresses in memory

                                          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.

                                          O Offline
                                          O Offline
                                          obermd
                                          wrote on last edited by
                                          #62

                                          If you want to do this in the dotNet framework and have it cross platform you're going to want to use one of the newer frameworks anyway as the older ones are not generally cross platform. I don't see the problem here.

                                          H 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups