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. General Programming
  3. .NET (Core and Framework)
  4. Reference variables aready initialized

Reference variables aready initialized

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpquestionperformance
4 Posts 3 Posters 0 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.
  • K Offline
    K Offline
    KaptinKrunch
    wrote on last edited by
    #1

    I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??

    R M 2 Replies Last reply
    0
    • K KaptinKrunch

      I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      No it wont take up much memory! If you pass your HashTable to another form only a reference to that single HashTable is passed. So the memory usage is just 4 byte (on a 32 bit os). This also means changing the HashTable in one place also changes it everywhere else you passed the reference to. If you still dont want to pass the HashTable around and you only need one instance of it in your whole application declare the variable in your main form public static. This way everyone can access it with MyMainFormClassName.MyPublicHashTableVariable.

      K 1 Reply Last reply
      0
      • K KaptinKrunch

        I'm looking for a way using C# or VB.net to reference variables. More specificly, I have a loaded hashtable that was created on my main form. When I open a new form, I need to have access to that information in the hastable. I don't want to pass the table between forms as this would create copies of the original and end up using more memory. What is the best way to accomplish this??

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        KaptinKrunch wrote: don't want to pass the table between forms as this would create copies of the original and end up using more memory. Except for value types, everything in .NET is an object (and even value types can be boxed to be objects). All objects are already passed as references. That's why you don't need pointers, or * to dereference a pointer, and that's why you don't need new and delete--the GC keeps track of the references to an object. Marc MyXaml Advanced Unit Testing YAPO

        1 Reply Last reply
        0
        • R Robert Rohde

          No it wont take up much memory! If you pass your HashTable to another form only a reference to that single HashTable is passed. So the memory usage is just 4 byte (on a 32 bit os). This also means changing the HashTable in one place also changes it everywhere else you passed the reference to. If you still dont want to pass the HashTable around and you only need one instance of it in your whole application declare the variable in your main form public static. This way everyone can access it with MyMainFormClassName.MyPublicHashTableVariable.

          K Offline
          K Offline
          KaptinKrunch
          wrote on last edited by
          #4

          Thanks for the advise!!

          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