Results 1 to 19 of 19

Thread: Too many functions!

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Post Too many functions!

    Original article

    As one of the more experienced C# coders in his group, Yakir is often asked programming questions. Recently, his colleague James asked him the best way to store hundreds of thousands of items in memory, to which Yakir replied "It depends on how you want to access your data. If you want to access your data by index, you should store it in an ArrayList. If its easier to store things as a key-value pair, then you should use a Hashtable."

    James' particular application called for a Hashtable, so he decided to implement that. A few hours later, however, he ran into some trouble. "This Hashtable isn't really working," James explained, "do you know if there's something more efficient?"

    "Errr," Yakir questioned, "there isn't really anything more efficient than a Hashtable. What exactly is the problem?"

    "It's just too slow," James replied, "once I have real data in there, it takes almost five seconds to add, remove, or find, an item."

    Yakir knew something was definitely wrong and sat with James to look at his code. Here's what he saw...

    Code:
    class HashTable
      {
        public object[] keys;
        public object[] values;
    
        public HashTable()
        {
          keys = new object[0];
          values = new object[0];
        }
    
        public void Add(object key, object value)
        {
          Array.Resize(ref keys, keys.Length + 1);
          Array.Resize(ref values, values.Length + 1);
          keys[keys.Length - 1] = key;
          values[values.Length - 1] = value;
        }
    
        public void Remove(object key)
        {
          object[] tempKeys = new object[0];
          object[] tempValues = new object[0];
          for (int i = 0; i <= keys.Length - 1; i++)
          {
            if (!keys[i].Equals(key))
            {
              Array.Resize(ref tempKeys, tempKeys.Length + 1);
              Array.Resize(ref tempValues, tempValues.Length + 1);
              tempKeys[tempKeys.Length - 1] = keys[i];
              tempValues[tempValues.Length - 1] = values[i];
            }
          }
          keys = tempKeys;
          values = tempValues;
        }
    
        public object GetItem(object key)
        {
          for (int i = 0; i <= keys.Length - 1; i++)
          {
            if (keys[i].Equals(key))
            {
              return values[i];
            }
          }
          return null;
        }
    
        public int NumberOfItems
        {
          get
          {
            return keys.Length;
          }
        }
      }
    "Uhhh," Yakir said, baffled. "Why didn't you use the built-in Hashtable class from System.Collections that I showed you?"

    "I checked it out," James explained, "but it had too many functions, which means it's slow. My class only has 3 functions, so it's much more efficient."
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Too many functions!

    Less is more.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Too many functions!

    Can anybody actually see the link in that post?
    My usual boring signature: Nothing

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Too many functions!

    Well, no, since it contains a word that VBF's nanny-ware regards as slightly rude.

    Replacing the three asterisks in the URL with "doubleyou tee eff" seems to yield a post remarkably similar to the drivel that kasracer wasted all our time with.
    I don't live here any more.

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Too many functions!

    crap

    No original article for you then.

    Daily Whiskey Tango Foxtrot DOT Com
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Too many functions!

    Oh good. For a moment there I began to suspect QWest of being as incompetent as usual. I'm too lazy to look up Kleinma's post about the nefarious ISP that was redirecting some types of errors to their custom search engine, but QWest has just started doing that, too. This was the second post in 24 hours with a link that took me to their search engine, and I was beginning to wonder if they had just decided to re-direct pretty nearly anything. They really are laughably inept, but the errors have been mostly in my favor, so far.
    My usual boring signature: Nothing

  7. #7
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Re: Too many functions!

    Quote Originally Posted by Article
    it had too many functions, which means it's slow. My class only has 3 functions, so it's much more efficient.
    At last! Someone that agrees with me!!!

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Too many functions!

    I name all my functions with a prefix 'static' because that makes it faster.

    Code:
    public int StaticGetEmployeeSalary(int employeeID)
    {
    //...
    }

  9. #9
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Too many functions!

    If you prefix them with virtual they are faster again because they are not really there....

  10. #10
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Too many functions!

    Quote Originally Posted by BillGeek
    At last! Someone that agrees with me!!!

  11. #11
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Too many functions!

    HTML is faster than C! Plus it's OOP too!
    I don't live here any more.

  12. #12
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Too many functions!

    Everytime you read HTML god kills a kitten. Just be warned.

  13. #13
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Too many functions!

    Quote Originally Posted by DeanMc
    Everytime you read HTML god kills a kitten. Just be warned.
    That must be a lot of kittens then. Are you trying to say that Icanhascheezburger.com just recycles the 3 cats over and over again??

  14. #14
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Too many functions!

    HTML is faster than C! Plus it's OOP too!
    I recently read a CV where the applicant had listed one of his skills as OOPS.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Too many functions!

    Quote Originally Posted by mendhak
    I name all my functions with a prefix 'static' because that makes it faster.

    Code:
    public int StaticGetEmployeeSalary(int employeeID)
    {
    //...
    }
    I finish all my functions with DoCommand.RunFaster..... and it works!

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Too many functions!

    Quote Originally Posted by DeanMc
    If you prefix them with virtual they are faster again because they are not really there....
    Only when being used to write vaporware.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Too many functions!

    When I want to hide a function I use:
    Code:
    void _______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________HiddenFunction(void) {
        ....
    }
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Too many functions!

    you could also try applying the <nopeeking> attribute to it as well.... as does this attribute:
    <jedi-mind-trick("This is not the function you are looking for.")>

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Too many functions!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width