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 8904417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:07:29+00:00 2026-06-15T02:07:29+00:00

I have an Id mapping cache that’s taking up a bit too much memory.

  • 0

I have an Id mapping cache that’s taking up a bit too much memory. It’s used to house a combination of 3 different types of Id’s for an object and the mappings for them are read in from a table, and cached in 6 different dictionaries for quick look-up/translation from any 1 Id type to another (performance is important for my application).

I wanted to rewrite it to something that has a smaller memory footprint so I did implement a consolidated list of the Id’s and used a linq/lambda expression to pull out the values I wanted. It looks like this for now.

public struct IdMappings
{
     public int Id1;
     public int Id2;
     public int Id3;
}

//new cache    
private static List<IdMappings> AllIdMappings = null;

//current cache implementation
private static Dictionary<int, int> Id1ToId2 = null;
private static Dictionary<int, int> Id1ToId3 = null;
//etc.

public static void FillCache(DataSet data)
{
     foreach (DataRow r in data.Tables[0].Rows)
     {
          //fill list and/or dictionaries with id's
     }
}

Example lookup would then be:

public static int GetId2FromId1(int id1)
{
    return AllIdMappings.FirstOrDefault(m => m.Id1 == id1).Id2;
    //or
    return Id1ToId2[id1];
}

This does what I need in terms of reducing memory usage, but performance for lookups has suffered as a result so I’m seeing how to implement something different. Is there a way to do multi-indexing keys, or multi-key lookup that’s relatively faster than iterating through a list?

  • 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-06-15T02:07:30+00:00Added an answer on June 15, 2026 at 2:07 am

    If you add these three dictionaries:

    private static Dictionary<int, IdMappings> Id1Lookup = null;
    private static Dictionary<int, IdMappings> Id2Lookup = null;
    private static Dictionary<int, IdMappings> Id3Lookup = null;
    

    And have the dictionary values be the same references, it should use minimally more memory but retain the same lookup speed as your original implementation.

    If I’m thinking about this right, this should use half the memory of your 6 dictionary solution, but twice a List<IdMappings> type solution.

    As @SWeko points out, IdMappings needs to be a class not a struct to ensure the reference pointer is used rather than copies of it.

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

Sidebar

Related Questions

Quick background I have a concurrent map I used to cache some values that
I would like to have a mapping function that does this: public static void
I want to enable data cache. I dont have much experience with ARM as
I have the fallowing NHibernate-Mapping: <class name=Activity table=Activity lazy=false > <cache usage=read-write/> <id name=Id
I have an application that will download and cache, at a minimum, 250,000 8KB*
I have NH mapping public class TblContentMap : ClassMap<TblContent> { public TblContentMap() { Table(tbl_content);
I have hash mapping H = { alc => AL, alco => AL, alcoh
I would like to have a mapping which maps two string into one string.
I have a short access/mySQL question. I have a mapping table on the format
I have a class ClassA mapped to TableA. I also have a mapping for

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.