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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:07:49+00:00 2026-05-14T18:07:49+00:00

I want to associate custom data to a Type, and retrieve that data in

  • 0

I want to associate custom data to a Type, and retrieve that data in run-time, blazingly fast.

This is just my imagination, of my perfect world:

var myInfo = typeof(MyClass).GetMyInformation();

this would be very fast… of course this does not exist! If it did I would not be asking. hehe 😉

This is the way using custom attributes:

var myInfo = typeof(MyClass).GetCustomAttribute(“MyInformation”);

this is slow because it requires a lookup of the string “MyInformation”

This is a way using a Dictionary<Type, MyInformation>:

var myInfo = myInformationDictionary[typeof(MyClass)];

This is also slow because it is still a lookup of ‘typeof(MyClass)’.

I know that dictionary is very fast, but this is not enough… it is not as fast as calling a method. It is not even the same order of speed.

I am not saying I want it to be as fast as a method call. I want to associate information with a type and access it as fast as possible. I am asking whether there is a better way, or event a best way of doing it.

Any ideas??

Thanks!

EDIT:

The typeof(MyClass) I mentioned in all of previous snippets, are actualy variable… I don’t know that it is a specific MyClass type, it could be any type:

Type myType = typeFromSomewhere;

i.e. MyClass in this case just says that the class is made by me, and any other types that could come into this situation is also made by me… so it reads

typeof( One of My Own Classes, that I don’t know witch one is it, but it is mine for sure )

EDIT: CONCLUSION

Some performance results related to dictionaries:

Dic.buckets | Dic.Count | Dic.Key | Ops(x17)/s | Avg.Time | Min.Time | Max.Time
-----------------------------------------------------------------------------
     17519  |    12467  |   Type  |    1051538 |  0.95μs  |  0.86μs  |  0.42ms
       919  |      912  |   Type  |     814862 |  1.23μs  |  1.14μs  |  0.46ms
   1162687  |      912  |   Type  |    1126382 |  0.89μs  |  0.81μs  |  0.33ms
       919  |      912  |   Type  |     806992 |  1.24μs  |  1.16μs  |  0.21ms
        17  |       17  |   Type  |     872485 |  1.15μs  |  1.06μs  |  0.31ms
-----------------------------------------------------------------------------
     36353  |    18160  |  String |     227520 |  4.40μs  |  3.98μs  |  0.47ms
       919  |      911  |  String |     219159 |  4.57μs  |  4.14μs  |  0.29ms
   1162687  |      911  |  String |     236384 |  4.23μs  |  3.82μs  |  0.41ms
       919  |      911  |  String |     223042 |  4.49μs  |  4.10μs  |  0.43ms
        17  |       17  |  String |     229985 |  4.35μs  |  3.94μs  |  0.28ms

Interface Call:

ops(x17)/s: 2896001
Average: 0.35μs
Min: 0.34μs
Max: 1.20μs

Virtual Call:

ops(x17)/s: 3115254
Average: 0.32μs
Min: 0.32μs
Max: 0.65μs

I see that I have under-estimated Dictionaries!!! =)

It seems that Dictionary of Type to anything is 3x to 4x slower than a virtual method call.

This is not the case using Dictionary of strings. That ones are 10x to 12x slower than a virtual method call.

So I have prooved me wrong!

And, NO I AM NOT MAKING A MISSILE!!! someone has supposed this in a comment bellow =)

Thanks everybody.

  • 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-14T18:07:50+00:00Added an answer on May 14, 2026 at 6:07 pm

    Dictionary<Type,Object> works for me.

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

Sidebar

Ask A Question

Stats

  • Questions 373k
  • Answers 373k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It depends on your platform. The iPhone has very different… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer You can use this method with another parameter IplImage* cvLoadImage(const… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer There isn't a single place where .framework folders/files are, they… May 14, 2026 at 7:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.