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. C#
  4. compute huge datastructure once on dll-load

compute huge datastructure once on dll-load

Scheduled Pinned Locked Moved C#
data-structuresquestion
7 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.
  • R Offline
    R Offline
    Rupel
    wrote on last edited by
    #1

    hi, i'm writing a dll and there's a huge but constant data structure that is used from time to time inside the library. when i put it into an ordinary class, this data-structure (it's a tree) has to be rebuilt everytime an object of the class is constructed. there's no main-function or app-object to keep the tree reference throughout the use of the dll. reference lost, garbage-collector feeded ;) what's the most effective way to solve this? :wq

    L A 2 Replies Last reply
    0
    • R Rupel

      hi, i'm writing a dll and there's a huge but constant data structure that is used from time to time inside the library. when i put it into an ordinary class, this data-structure (it's a tree) has to be rebuilt everytime an object of the class is constructed. there's no main-function or app-object to keep the tree reference throughout the use of the dll. reference lost, garbage-collector feeded ;) what's the most effective way to solve this? :wq

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Hi Have tried putting it in a different class and exposed it a static member? You dont so whether u make changes to it, or it just serves as a "lookup table"... Maybe it helps ;) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

      R 1 Reply Last reply
      0
      • L leppie

        Hi Have tried putting it in a different class and exposed it a static member? You dont so whether u make changes to it, or it just serves as a "lookup table"... Maybe it helps ;) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

        R Offline
        R Offline
        Rupel
        wrote on last edited by
        #3

        yes it is kind of a lookup-table (a lookup-tree if you like) but when i have that thing a static member of a class, it still has to be created once. when should i do that? in the constructor? but then the procedure takes place each time an object of this class is created via new. or do you think an additional static bool set to true after the first creation may help? lets say Class A { static Tree lookupTree; static bool created=false; A() { if (!created) { ExpensiveTreeCreationFunction(); created = true; } } ... } and then i can use A control = new A(); A.foo(); //using lookupTree as often as i like without ExpensiveTreeCreationFunction(); called each time? :omg: :wq

        L 1 Reply Last reply
        0
        • R Rupel

          yes it is kind of a lookup-table (a lookup-tree if you like) but when i have that thing a static member of a class, it still has to be created once. when should i do that? in the constructor? but then the procedure takes place each time an object of this class is created via new. or do you think an additional static bool set to true after the first creation may help? lets say Class A { static Tree lookupTree; static bool created=false; A() { if (!created) { ExpensiveTreeCreationFunction(); created = true; } } ... } and then i can use A control = new A(); A.foo(); //using lookupTree as often as i like without ExpensiveTreeCreationFunction(); called each time? :omg: :wq

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          yes ! almost, but it would be better to check when calling foo() instead of a static constructor (some things never makes sense :) ) or just add a static method to create it...there are many choices :) Do whats best for you. MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

          R 1 Reply Last reply
          0
          • L leppie

            yes ! almost, but it would be better to check when calling foo() instead of a static constructor (some things never makes sense :) ) or just add a static method to create it...there are many choices :) Do whats best for you. MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

            R Offline
            R Offline
            Rupel
            wrote on last edited by
            #5

            checking in foo() is ok. i just tried and it seems to work. to get things clear: when a class consists of a static member, this member is stored somewhere else than the objects of that class (which are destroyed by the GC when references go to zero) and are freed/destroyed when? at the end of the program-run? i just want to understand that...:) :wq

            1 Reply Last reply
            0
            • R Rupel

              hi, i'm writing a dll and there's a huge but constant data structure that is used from time to time inside the library. when i put it into an ordinary class, this data-structure (it's a tree) has to be rebuilt everytime an object of the class is constructed. there's no main-function or app-object to keep the tree reference throughout the use of the dll. reference lost, garbage-collector feeded ;) what's the most effective way to solve this? :wq

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              The best solution to this is to use a static member and static constructor. Create some class which has the static member of the type you are referring to. Then put hte build datastructure code in the static COnstructor. This way the table will only be built ont time and you odn't have to worry about when to build it. The static constructor will be called before anything in the class is accessed.

              L 1 Reply Last reply
              0
              • A Anonymous

                The best solution to this is to use a static member and static constructor. Create some class which has the static member of the type you are referring to. Then put hte build datastructure code in the static COnstructor. This way the table will only be built ont time and you odn't have to worry about when to build it. The static constructor will be called before anything in the class is accessed.

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                Thanx , didnt know that about the static constructor :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

                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