Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 09:48

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ - Pointers Question

Discussion on C++ - Pointers Question within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
xBlackPlagu3x's Avatar
 
elite*gold: 0
Join Date: Jan 2011
Posts: 286
Received Thanks: 71
C++ - Pointers Question

So I've been studying C++ for the past couple of days, and I'm now on pointers... So like when you pass by value, technically you are having to use double the resources than when you pass by reference. Could that statement be correct?
xBlackPlagu3x is offline  
Old 05/02/2012, 14:08   #2
 
elite*gold: 20
Join Date: Aug 2007
Posts: 1,749
Received Thanks: 2,199
Quote:
Originally Posted by xBlackPlagu3x View Post
So I've been studying C++ for the past couple of days, and I'm now on pointers... So like when you pass by value, technically you are having to use double the resources than when you pass by reference. Could that statement be correct?
Not really, it depends on what you're passing. Passing an int pointer compared to an int wouldn't be faster, and would only be reasonable to do if you actually needed to modify the int as a return value of the function.

Passing structures/classes as pointers is usually faster though.
IAmHawtness is offline  
Old 05/02/2012, 15:58   #3
 
xBlackPlagu3x's Avatar
 
elite*gold: 0
Join Date: Jan 2011
Posts: 286
Received Thanks: 71
Quote:
Originally Posted by IAmHawtness View Post
Not really, it depends on what you're passing. Passing an int pointer compared to an int wouldn't be faster, and would only be reasonable to do if you actually needed to modify the int as a return value of the function.

Passing structures/classes as pointers is usually faster though.
One of the greatest things that's happened to me in the past 3 days is that I now understand what you're talking about lol. :P Thanks, I'll definitely keep this in mind.
xBlackPlagu3x is offline  
Old 05/02/2012, 16:11   #4
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
No, because when the compiler translates passing a simple type to assembly, it's just one instruction more, if the compiler doesn't optimize it (not sure if it does). As IAmHawtness said, passing classes and structs as pointers is usually faster.

To compare C++ with C#, C# passes classes as reference types by default, and simple types and structs as value types, and as you know - to modify a simple type or struct by reference, use the "ref" keyword.
Lateralus is offline  
Old 05/02/2012, 22:13   #5
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,284
Received Thanks: 4,196
I actually studied the compiler you're using for ANSI C++. Yes. If you create a new function and you don't pass variables by reference, it will copy the value of the passing variables to new locations in memory (with the exception of few data types). Arrays are always passed by reference. Structs can be passed by value but it's costly if the structure is large and you're using the function in something like a search. Pointers are alternatives for passing structs by value. If you pass the pointer of a struct, that's more efficient than passing the entire struct.
Spirited is offline  
Reply


Similar Threads Similar Threads
Pointers
05/20/2010 - Kal Online - 8 Replies
Da ich bei mir sobald ich einen Pointer suchen will nen bluescreen bekomme wollte ich fragen ob vllt jemand ein CT mit Speed pointer und Z position pointer hat ;) ps. gibt es eig. Pointer für Cooldown? ;) bin grad dabei nen kleines tool mit AutoIt zu machen dafür brauch ich die Pointer ;)
pointers
08/02/2009 - Grand Chase Philippines - 38 Replies
kagabi pa ko naghahanap pano gumawa ng CT na may pointer.. patulong nga..
pointers
06/22/2009 - Grand Chase Philippines - 4 Replies
im just wondering how to use pointers ? anyone can help me?
Help about pointers
05/17/2009 - Grand Chase Philippines - 5 Replies
can anyone teach me how to do this para d na poh aq mauli ulit mag scan ng address evertime I open PChack
[QUESTION] Pointers
10/02/2008 - Kal Online - 4 Replies
Hello, can anyone tell me how can i make pointers for storms? And other question... Bloodx relased new version of pimphack? Cause i play on xiu and old dont work for me:(



All times are GMT +2. The time now is 09:49.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.