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

  • SEARCH
  • Home
  • 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 884829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:48:28+00:00 2026-05-15T12:48:28+00:00

Uhm, so I had problems with the title, but this was my best shot!

  • 0

Uhm, so I had problems with the title, but this was my best shot!

Situation: I am writing a library so that I easily can re-use my code in future projects, without thinking about the internals. This library is supposed to be able to create objects at runtime and then access them to do tasks via a method. All by using a easy-to-use identifier.

Something like this:

class Manager
{
    Object[] Foo;
    // Other stuff + initialization logic

    CreateFoo(/*Some parameters here + Identifier*/)
    {
        // Create a new Foo here;
    }
    AddBar(/*Moar parameters + Foo identifier*/)
    {
        Foo[StoID(identifier)].AddBar(/*Params*/);
    }

}

class Software
{
    Software()
    {
        // Create a lot of Foos.
        while(1)
        {
             manager.CreateFoo(/*Params*/);
        }
    }
    void OhHai()
    {
        // This method can be called a LOT (100 times per update) or not at all       
        // depending on circumstances.
        manager.AddBar(/*Params*/);
    }
}

Disclaimer: No, that is NOT actually my code silly!

Problem: I might want to access my Foo Objects a lot and the performance is crucial, but so is manageability and ease of use. My first thought, for example, was to use strings and array indexes to create a small, dynamic conversion-library. However this would mean a lot of iterations – depending on how many Foos are created – and string-comparing.

Example:

class Software
{
    Manager manager;
    Software()
    {
        manager.CreateFoo("Lol", /*Parameters*/);
        manager.CreateFoo("Cat", /*Parameters*/);
    }
    void OhHai()
    {
        manager.AddBar("Lol", /*Parameters 1*/;
        manager.AddBar("Cat", /*Parameters 2*/;
    }
}

The performance of directly accessing a Foo with an index must be far greater than first converting a string to id. However strings are easily managed by humans so ease of use would be perfect that way.

What I’m asking: How are these things usually handled and does anyone have a suggestion for how I should design this?

Edit: Basically I’m trying to find an easy way for my manager to know which Foo to add a Bar to! 🙂

  • 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. Editorial Team
    Editorial Team
    2026-05-15T12:48:28+00:00Added an answer on May 15, 2026 at 12:48 pm

    I might be missing something here, but it looks like what you want to use as your backing store is a Dictionary object instead of Arrays.

    The time to index into a dictionary is O(1). You can’t beat constant time. 🙂

    Well, you can if your constant time is REALLY long, but it’s not for dictionary retrieval. Just make sure your GetHashCode method produces a good hash and you should be golden.

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

Sidebar

Related Questions

Uhm I'm not sure if anyone has encountered this problem a brief description is
I have to extend an existing program (Java-based, but this shouldn't count). This program
Uhm, so I have run into this before. I want to do this. PhoneNumber
I found an interesting pairs matching game at http://xepthu.uhm.vn . The rule is simple,
I'm trying to turn off marginpar when starting a new multicols environment with this
Dear all, Given a variable that takes on, say, three values, I'm trying to
I'll start with that I have no idea what would be the proper keywords
im just wondering as I couldn't find an answer on google (well, maybe Ive
On my Vista machine I cannot install the .Net framework 3.5 SP1. Setup ends
Referring to TLB and maintenance issues ... My question to people (often) using the

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.