Thread: need to get the type of a variable inside the data structure

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Generally speaking - unless you are using templates or specialisations of templates - code that needs to deduce the type of a variable is normally badly broken. There are usually design alternatives.

    Why don't you describe what you are trying to achieve, rather than how you have decided to achieve it? Odds are, someone will be able to offer a better approach (or point out why you're trying to achieve something silly, which is still a possibility).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #17
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by baxy View Post
    so far with my c code i always received good critiques on how small amount of memory it takes. you can call it a bad design but ...
    It could be good or bad design, actually. It depends on what you're trying to optimize for, and what trade-offs you're making in the process. You're saving memory, but at certain costs:
    1. Some increased CPU time to read from the data structure
    2. Depending on data access patterns, potentially decreased cache performance, causing more expensive RAM reads
    3. Greater complexity of code to write and maintain

    So to know whether the tradeoff is worth it, you'd need to weigh exactly how much memory you're saving versus how much performance and maintainability you're sacrificing. For a huge memory gain, this might be worth it. For a trivial memory gain, it's a terrible design.

    #3 would generally be my largest concern in a case like this - in general, if you are doing an "average" application, for every 1 hour spent on building your code base, you will spend 9 hours maintaining that code base. Every hour you spend on this is an hour you're not working on a different feature; is this what your 'customers' would feel is the best possible use of that time?
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting the data type of an unknown variable
    By adarpodracir in forum C Programming
    Replies: 6
    Last Post: 04-07-2012, 07:17 PM
  2. Hardest Data structure type
    By camel-man in forum C Programming
    Replies: 30
    Last Post: 06-29-2011, 12:59 AM
  3. Replies: 2
    Last Post: 05-14-2011, 09:26 PM
  4. Replies: 1
    Last Post: 04-29-2011, 08:41 PM
  5. Variable Data Structure
    By JimpsEd in forum C Programming
    Replies: 4
    Last Post: 05-27-2006, 09:56 AM