Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 177247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:01:17+00:00 2026-05-11T14:01:17+00:00

I need to implement a large collection of Widget objects, each of which contain

  • 0

I need to implement a large collection of Widget objects, each of which contain a unique file path string (‘FilePath’). I need to be able to do the following:

  1. Retrieve a Widget object quickly given the file path
  2. Change the file path of a Widget without creating a new object (multiple other objects may contain references to a single Widget, and tracking them down would impact performance)
  3. Given a Widget reference, determine it’s file path

I first thought of using a generic SortedList using the file path as a key, but duplicating the path for many thousands of objects could quickly eat up memory. I considered removing the path from the object and only storing it in the list of keys, but that would make requirement 3 above hard to accomplish.

What I’m leaning towards now is rolling my own class derived from List<> that adds the Widget objects in a sorted order, and retrieves them with a binary search. Requirement 2 can be accomplished simply by removing an object from the list, changing it’s file path, and adding it back to the list.

But I’m relatively new to C# and I wanted to check with the great minds here and see if I’m missing another obvious solution.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:01:18+00:00Added an answer on May 11, 2026 at 2:01 pm

    ‘Duplicating’ the strings will not use twice the memory: Since strings are immutable objects in c#, you will just store another reference (i.e. pointer, 4 or 8 byts) per entry in the dictionary:

    Dictionary<string, Widget> dict = new Dictionary<string, Widget>(); Widget myWidget = GetSomeWidget(); dict.Add(myWidget.Name, myWidget); 

    You will always be reusing the string object from the widget’s property, so just go on with the dict and store the path as property inside the widget.

    If you don’t need to enumerate the widgets in sorted order, don’t use the SortedList, it will be slower than the Dictionary (O(n log n) insertion/deletion/retrieval vs. O(n) average time)

    Changing the widget’s path will need you to remove it from the dictionary and add it with the changed path, but this is an average constant time operation, so it should be pretty fast.

    And just to mention it: Even if you would have to spend one MB of additional memory for getting more performance or using a better-suited (and well-tested) data structure, I don’t think that would be a great problem considering the amount of memory other applicatins are using (wasting?) these days …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combo box that I bind to an observable collection, which gets
What's the best way to keep track of unique tags for a collection of
I have a collection of items (big rationals) that I'll be processing. In each
I need an idea for an efficient index/search algorithm, and/or data structure, for determining
I have a rather enormous project in which I'm trying to retrofit in-memory data.
When creating an FixedThreadPool Executor object in Java you need to pass an argument
I've run across this design issue a number of times and was wondering if
I have a small project I am doing in Python using web.py. It's a
Given a range of IP addresses entered by a user (through various means), I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.