Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,410 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,219 people online right now. Registration is fast and FREE... Join Now!




Variable type for efficient code

 
Reply to this topicStart new topic

Variable type for efficient code

shanihg
21 Jan, 2008 - 02:54 AM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 5


My Contributions
Hi
Could anyone please advise when I am developing my code on Windows XP platform, would the generated code be most efficient if I declare most of my variables as DWORD or WORD?

Thanks
Shani
User is offlineProfile CardPM
+Quote Post

cricketfancy
RE: Variable Type For Efficient Code
21 Jan, 2008 - 03:11 AM
Post #2

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 15


My Contributions
QUOTE(shanihg @ 21 Jan, 2008 - 03:54 AM) *

Hi
Could anyone please advise when I am developing my code on Windows XP platform, would the generated code be most efficient if I declare most of my variables as DWORD or WORD?

Thanks
Shani


i think dword....................


User is offlineProfile CardPM
+Quote Post

baavgai
RE: Variable Type For Efficient Code
21 Jan, 2008 - 04:53 AM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,274



Thanked: 135 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Well, WORD is 2 bytes, and DWORD is double WORD, or 4 bytes. So WORD should take of less storage. However, if the functions you're using all want DWORD, use that. Unless you're writing a driver or something, it's really not a point to be worried about. Indeed, depending on the compiler, it might allocate differently than you'd expect, just to be safe.

You will see untold numbers of C programs that use int, where they could have used byte. This is done for a kind of efficiency, it's easier just to deal with the one type.

Hope this helps.

User is offlineProfile CardPM
+Quote Post

Bench
RE: Variable Type For Efficient Code
22 Jan, 2008 - 02:42 AM
Post #4

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 683



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
QUOTE(shanihg @ 21 Jan, 2008 - 10:54 AM) *

Hi
Could anyone please advise when I am developing my code on Windows XP platform, would the generated code be most efficient if I declare most of my variables as DWORD or WORD?

Thanks
Shani

That's an unanswerable question, given the information you've provided. The answer depends entirely on the program, what data you'll be storing, the quantity of data you're talking about, and how that data will be used in your program.
in many cases, the answer will be 'It doesn't really matter'.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:42AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month