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. Storing references in a List [modified]

Storing references in a List [modified]

Scheduled Pinned Locked Moved C#
algorithmsperformancequestion
3 Posts 2 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
    rcollina
    wrote on last edited by
    #1

    Hello everyone, I am currently developing an interface for a third-party 3d engine. Current scenario: I need to store object references. For this to happen, I'm using List collections. These Lists might contain the same object reference (one list can have visible interface objects to render, and another one could have the same objects, a the z-sorting list for instance). Is this a correct way of storing multiple references, or is there a better method you can shed some light on (performance-wise, or just coding-wise)? Is this going to produce GC issues? I have read about WeakReferences in a reply over these forums but I'm not sure about their usage in this context. Thanks for reading and for any further reply, Rob

    C 1 Reply Last reply
    0
    • R rcollina

      Hello everyone, I am currently developing an interface for a third-party 3d engine. Current scenario: I need to store object references. For this to happen, I'm using List collections. These Lists might contain the same object reference (one list can have visible interface objects to render, and another one could have the same objects, a the z-sorting list for instance). Is this a correct way of storing multiple references, or is there a better method you can shed some light on (performance-wise, or just coding-wise)? Is this going to produce GC issues? I have read about WeakReferences in a reply over these forums but I'm not sure about their usage in this context. Thanks for reading and for any further reply, Rob

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Roberto Collina wrote:

      Is this a correct way of storing multiple references, or is there a better method you can shed some light on (performance-wise, or just coding-wise)? Is this going to produce GC issues?

      A reference just points (or refers) to the actual object. If you store an object reference on two different lists all that is happening is that you now have two places that point (refer) to the same actual object. It won't cause GC problems. The garbage collector will only remove an object when nothing refers to it any more. In terms of performance, if you need a list sorted by Z-Order and a list of visible only objects for different purposes then it will probably improve performance. You just need to ensure that the lists are kept up to date an in sync with each other.

      Roberto Collina wrote:

      I have read about WeakReferences in a reply over these forums but I'm not sure about their usage in this context.

      A weak reference is a reference to an object that CAN be garbage collected. In other words you cannot rely on the reference, it may suddenly become null without you realising. Obviously, if you have something that is a weak reference and you assign it to something then it becomes a stong reference and the garbage collector won't touch it. Weak references are rarely needed and from the information you've given I don't see why you would need them.


      Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

      R 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Roberto Collina wrote:

        Is this a correct way of storing multiple references, or is there a better method you can shed some light on (performance-wise, or just coding-wise)? Is this going to produce GC issues?

        A reference just points (or refers) to the actual object. If you store an object reference on two different lists all that is happening is that you now have two places that point (refer) to the same actual object. It won't cause GC problems. The garbage collector will only remove an object when nothing refers to it any more. In terms of performance, if you need a list sorted by Z-Order and a list of visible only objects for different purposes then it will probably improve performance. You just need to ensure that the lists are kept up to date an in sync with each other.

        Roberto Collina wrote:

        I have read about WeakReferences in a reply over these forums but I'm not sure about their usage in this context.

        A weak reference is a reference to an object that CAN be garbage collected. In other words you cannot rely on the reference, it may suddenly become null without you realising. Obviously, if you have something that is a weak reference and you assign it to something then it becomes a stong reference and the garbage collector won't touch it. Weak references are rarely needed and from the information you've given I don't see why you would need them.


        Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

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

        Thank you, Colin.

        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