Results 1 to 3 of 3

Thread: What is register int?

  1. #1
    Join Date
    Oct 2012
    Posts
    27
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default What is register int?

    What is a register int?
    What is the difference between a register int and a normal int?
    Why not use register int where we can instead of using a normal int?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: What is register int?

    What is a register int?
    register int storage area is CPU registers

    What is the difference between a register int and a normal int?
    The only diffrence is storage area. Normal ints are stored in RAM

    Why not use register int where we can instead of using a normal int?
    Typical CPU will have 5-30 (Completely depends on architecture) general pupose registers, so they are very few. One have use them wisely. Most of the compilers will handle this for you, they will try to fit normal int to registers, and if registers are not available normal int is used even for register int. (Note you may need to set the optimization level in compiler)

    Variables which are used very often (many statments) are typically declared as register int
    Examples:
    1. Loop control varables
    2. Array offset index
    3. Pointers (specially array pointers, memory pointers)

    Main reason behind this is that CPU can operate on data in registers only, so it has load the variables in to registers and then operate on them. If we already have frequenty used data in registers, loading time is saved (which is significant on CPUs using external memory)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Oct 2012
    Posts
    27
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is register int?

    Thanks for that very informative answer!

Similar Threads

  1. Cannot register Service name on System Bus
    By drf in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2012, 03:44
  2. Register QtCreator on Win7?
    By weaver4 in forum Newbie
    Replies: 7
    Last Post: 6th April 2012, 00:30
  3. [PyQt4]—Visual display of a register
    By osfd in forum Qt Programming
    Replies: 1
    Last Post: 10th January 2012, 18:35
  4. How to register a global hotkey?
    By Fazer in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2009, 13:55
  5. How to register a font with Qt?
    By Vadi in forum Qt Programming
    Replies: 5
    Last Post: 1st February 2009, 06:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.