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 5 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.
  • D Dewey

    That Ezra Taft Benson, while true, is one of the dumbest remarks I've seen, and is used by some groups to put down government. The point of government is to take your money and do what's best for the people as a whole. You can argue that isn't what happens in some cases, but that misses the point. Government generally is the only entity that takes risks when the reward isn't obvious. That where just about all of our technology comes from because industry won't invest without the promise of fairly quick rewards.

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

    I could write pages on this but I fear aside from not being read, it would wax far too political for the lounge. I was anarchist for 26 years. I didn't so much leave it behind as I evolved, just so you have some idea of where I'm coming from. I've never particularly been a fan of states. That having been said, you're essentially right, with the following caveats: Governments are complex adaptive systems. In lay terms, they consist of so many people that they take on a life of their own. The actions of the whole are not necessarily reflective of its individual agents. The problem with this is such systems either grow or they wither and die. Stasis is rare. And they defend themselves against attempts to undermine them. Positive** prospects like limiting government do not limit government, they create defacto private government with state power and no accountability. ** i'm not using the term like "good" - i'm using it as in active vs. passive That gets dangerous and ugly when the continuation of the system is more important to the system than acting out the will of the people it's supposed to represent. And all of them fall down under the right or rather, wrong conditions. No system can perfectly contain the potential for revolt. So with those limitations in mind, I think it's a good idea to be wary of government, but I think most people regard it as necessary because anarchism doesn't scale. :)

    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

      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.

      R Offline
      R Offline
      RedDk
      wrote on last edited by
      #21

      Ok, This is the Lounge. THIS post here is purely programmer speak so ... take it to a forum. Pick one.

      1 Reply Last reply
      0
      • D Dewey

        That Ezra Taft Benson, while true, is one of the dumbest remarks I've seen, and is used by some groups to put down government. The point of government is to take your money and do what's best for the people as a whole. You can argue that isn't what happens in some cases, but that misses the point. Government generally is the only entity that takes risks when the reward isn't obvious. That where just about all of our technology comes from because industry won't invest without the promise of fairly quick rewards.

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #22

        Dewey wrote:

        The point of government is to take your money and do what's best for the people as a whole.

        That's certainly not the point of the U.S. Federal gov't. The constitution makes it very clear that the Federal gov't is supposed to protect the people from foreign enemies, and not do much else that gets in the way of individual freedom and liberty. Of course certain forces have corrupted this to great extent.

        The difficult we do right away... ...the impossible takes slightly longer.

        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.

          R Offline
          R Offline
          RedDk
          wrote on last edited by
          #23

          Ok, This is the Lounge. THIS post here is purely programmer speak so ... take it to a forum. Pick one.

          H 1 Reply Last reply
          0
          • R RedDk

            Ok, This is the Lounge. THIS post here is purely programmer speak so ... take it to a forum. Pick one.

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

            my posts of this nature were already weighed in on by Chris. they've been ruled okay for the lounge, so if you don't like them skip them or block me.

            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.

            C 1 Reply Last reply
            0
            • H honey the codewitch

              i know that, but it's not efficient and doesn't solve the basic issue, which is persistent, rapidly searchable storage.

              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
              #25

              If you want something to be truly rapid, you'd perhaps need to look at a native programming language like C++. Yes, .NET is supposed to make things easier, but not necessarily faster executing.

              H 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                If you want something to be truly rapid, you'd perhaps need to look at a native programming language like C++. Yes, .NET is supposed to make things easier, but not necessarily faster executing.

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

                I'm not looking for something that's bit level optimized. I'm fine with looking at complexity as for example O(log N), and that's fine, without worrying about the .NET overhead on top of the base functionality. Nah, mem mapped files, if i could use them like they were intended but under .NET, would make my programming task easier. Not necessarily make the program faster.

                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

                  I'm not looking for something that's bit level optimized. I'm fine with looking at complexity as for example O(log N), and that's fine, without worrying about the .NET overhead on top of the base functionality. Nah, mem mapped files, if i could use them like they were intended but under .NET, would make my programming task easier. Not necessarily make the program faster.

                  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
                  #27

                  honey the codewitch wrote:

                  I'm fine with looking at complexity as for example O(log N), and that's fine, without worrying about the .NET overhead on top of the base functionality.

                  Doing a full u-turn, are we? This was your response to another person on this thread:

                  honey the codewitch wrote:

                  but it's not efficient and doesn't solve the basic issue, which is persistent, rapidly searchable storage.

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

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

                    honey the codewitch wrote:

                    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

                    Yes, and that's by design.

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

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

                      Environments designated to making simple things simple tend to make complicated things more complicated. Or maybe not, in the case of .NET, there's the unsafe keyword which allows you to work on raw pointers. However, that indeed doesn't help much with disk stuff. See it this way, C# is the polar opposite of C here. In C, complex things and simple things work about the same way at the cost of simple things being ridiculously complicated. I remember a project of mine where I combined the strengths of two worlds, I did my low-level in C (technically C++, but I had raw pointers at work), exposed a C interface and did my business logic in C#. Such a mixed design is of course too easy to get wrong, but I think I've managed to make it make sense.

                      H 1 Reply Last reply
                      0
                      • M Member 9167057

                        Environments designated to making simple things simple tend to make complicated things more complicated. Or maybe not, in the case of .NET, there's the unsafe keyword which allows you to work on raw pointers. However, that indeed doesn't help much with disk stuff. See it this way, C# is the polar opposite of C here. In C, complex things and simple things work about the same way at the cost of simple things being ridiculously complicated. I remember a project of mine where I combined the strengths of two worlds, I did my low-level in C (technically C++, but I had raw pointers at work), exposed a C interface and did my business logic in C#. Such a mixed design is of course too easy to get wrong, but I think I've managed to make it make sense.

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

                        I completely agree, and I've done similar. It's just that here, it's not really my goal to make something tied to the windows platform specifically, and pretty much no matter the route i take as soon as I'm relying on that mixed managed and unmanaged code I'm also inherently tying it to a platform. Sure I can cross compile the unmanaged code, but even then, it's one package per platform - not what i want.

                        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
                        • R Rajesh R Subramanian

                          honey the codewitch wrote:

                          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

                          Yes, and that's by design.

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

                          I'm aware of that. I worked on the Visual Studio team at microsoft. I know a little about .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.

                          R 1 Reply Last reply
                          0
                          • R Rajesh R Subramanian

                            honey the codewitch wrote:

                            I'm fine with looking at complexity as for example O(log N), and that's fine, without worrying about the .NET overhead on top of the base functionality.

                            Doing a full u-turn, are we? This was your response to another person on this thread:

                            honey the codewitch wrote:

                            but it's not efficient and doesn't solve the basic issue, which is persistent, rapidly searchable storage.

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

                            No I'm not, because in this case, there's an order of magnitude of difference in performance between using the windows memory paging system, and seeking around a disk file all the time. It changes the complexity. I'm not concerned about 10% improvements.

                            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

                              I completely agree, and I've done similar. It's just that here, it's not really my goal to make something tied to the windows platform specifically, and pretty much no matter the route i take as soon as I'm relying on that mixed managed and unmanaged code I'm also inherently tying it to a platform. Sure I can cross compile the unmanaged code, but even then, it's one package per platform - not what i want.

                              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
                              #33

                              Don't quote me, but I am rather sure that you can't do that in a platform-agnostic manner. Going with P/Invoke or a low-level library in C will require platform ties as the C API doesn't know of the concept you need (hey, the C standard doesn't even have a concept of alignment). From what I know, the C++ standard library doesn't have this concept either and the moment your standard libraries don't provide something, you have to work with IFDEFs for platforms. Be it with .NET, C++ or any other language.

                              H 1 Reply Last reply
                              0
                              • M Member 9167057

                                Don't quote me, but I am rather sure that you can't do that in a platform-agnostic manner. Going with P/Invoke or a low-level library in C will require platform ties as the C API doesn't know of the concept you need (hey, the C standard doesn't even have a concept of alignment). From what I know, the C++ standard library doesn't have this concept either and the moment your standard libraries don't provide something, you have to work with IFDEFs for platforms. Be it with .NET, C++ or any other language.

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

                                yeah but i think you can do p/invoke in mono to access ELF binaries (or whatever they'll called these days), etc. worst case I'd use #if in C# to plug in the right p/invoke attributes for the platform So like i said, it might be that I could cross compile the unmanaged bits, but in any case it doesn't give me what i want here.

                                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 but i think you can do p/invoke in mono to access ELF binaries (or whatever they'll called these days), etc. worst case I'd use #if in C# to plug in the right p/invoke attributes for the platform So like i said, it might be that I could cross compile the unmanaged bits, but in any case it doesn't give me what i want here.

                                  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
                                  #35

                                  As I was saying, I am darn sure that it's not realistic to get this rather special use case of yours in a platform-agnostic manner. You don't need to cross-compile though. Of course can you P/Invoke in Mono and Mono has it's own share of IFDEFs to tell platforms apart. So compile ONE executable to run on Mono (or .NET Core which also has ways to tell platforms apart) but with your NativeMethods class being full of IFDEFs.

                                  H 1 Reply Last reply
                                  0
                                  • M Member 9167057

                                    As I was saying, I am darn sure that it's not realistic to get this rather special use case of yours in a platform-agnostic manner. You don't need to cross-compile though. Of course can you P/Invoke in Mono and Mono has it's own share of IFDEFs to tell platforms apart. So compile ONE executable to run on Mono (or .NET Core which also has ways to tell platforms apart) but with your NativeMethods class being full of IFDEFs.

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

                                    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.

                                    M 1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      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.

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

                                      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

                                      H 1 Reply Last reply
                                      0
                                      • M Member 9167057

                                        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

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

                                        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.

                                        M 1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          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.

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

                                          Why do you insist on an unmanaged binary? Why don't you want to do your unmanaged ABI calls with P/Invoke?

                                          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