Jump to content

[C++] Would using pointers make sense here?

NeatSquidYT

Your Github link is broken

Never Mind

Build: i5-4460 | GT 720 | Logitech G710+ Keyboard | Corsair M65 Mouse | Dell e2314h Monitor | Windows 10

Generic Dell: Mobo, 8gb RAM, 430w PSU, 1TB Storage, XPS 8700 Case

Link to comment
Share on other sites

Link to post
Share on other sites

Uh...arrays are basically pointers with allocated memory.

 

I don't quite get the question. What else are you trying to use pointers for? Make a linked list/graph? That would be good , but you are just fine with std::vector.

 

Anyway, you should probably be making a structure/class for the flashcards :

struct flashcard{    char *question;    char *answer;    flashcard(char *_question , char *_answer) : answer(_answer) , question(_question){}};

Then make an array of those.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Don't use pointers unless you need to, and I think you can mostly (they will come up in a few places, I'm sure) get away without using them in your program. That will reduce some headaches, you don't have anything to win with using them in your case. Unless you want to learn them this way, then please do use them!

 

Generaly you use them for bigger structures or buffers, because it's easier to reference where they are put rather than move the entireity of the thing, they may take up lots of space and copying them is not a good idea for performance. Also they are often used when you have no direct control over that memory, like some libraries don't allow you to handle their structures or maybe even some other program is handling them (that's one way IPC can be done, that's the shared memory way). They make no sense for small variables, unless they have to be referenced inside the function (C++ has a way with this without using pointer semantics, thats the '&' that goes after the type in a function declaration, it's just a pointer underneath). Well there's more to it than that, but for most cases that's it, let's narrowly avoid a wall of text here. Basically when you say "I want that piece of memory" you use a pointer, also think if that piece of memory needs to be referenced at all.

Link to comment
Share on other sites

Link to post
Share on other sites

Pointers would be used if say each card was drawn to the screen and the backsides were all the same.

 

Instead of each card having their own image taking up extra memory each card could just have a pointer that points to a static image.

This kind of optimization is easy and essential if you try to scale your game by having like 10,000 cards on screen at once.

 

Edit: first post with christmas profile pic of 2015

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×