Memory Allocation
Author |
Message |
Panphobia

|
Posted: Sat Apr 06, 2013 11:21 pm Post subject: RE:Memory Allocation |
|
|
crap yea I was thinking of setting an int array to null, because that would be 0 I was not thinking, sorry about that. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Sun Apr 07, 2013 12:10 am Post subject: RE:Memory Allocation |
|
|
I am getting the feeling POINT may be better implemented as a class.. |
|
|
|
|
 |
Cancer Sol

|
Posted: Sun Apr 07, 2013 12:24 pm Post subject: Re: RE:Memory Allocation |
|
|
wtd @ 4/7/2013, 12:10 am wrote: I am getting the feeling POINT may be better implemented as a class..
I don't even know what a Class is xD
Actually, I know what the problem is for my program. It isn't about new and/or delete,
it's just a function I'm not using properly.
Basically, this is what I did:
c++: |
int coord=0;
POINT *cursorpos = new POINT [20];
GetCursorPos(*cursorpos[coord]);
coord++;
|
Which there's something wrong, like I can't use an array within GetCursorPos.
It works when I don't use an array and inside GetCursorPos, I would do this:
c++: |
GetCursorPos(&Example);
|
But I want to store multiple coordinates. How do I do that? I've tried experimenting with it for so long yesterday. |
|
|
|
|
 |
DemonWasp
|
Posted: Sun Apr 07, 2013 3:32 pm Post subject: RE:Memory Allocation |
|
|
If you want to pass a reference to GetCursorPos (which should be declared as follows):
code: | void GetCursorPos ( POINT &p ) |
Then you can pass an array element by this:
code: | GetCursorPos ( cursorpos[coord] ); |
The code you posted tries to dereference 'cursorpos' twice (*cursorpos[coord]), but it only has one level of indirection (basically, one * in its declaration).
If you were passing by pointer rather than reference, then GetCursorPos would look like:
code: | void GetCursorPos ( POINT *p ) |
And you would pass an array element by this:
code: |
// This says "get me the address of the [coord] element of the 'cursorpos' array"
GetCursorPos ( &(cursorpos[coord]) );
|
or
code: |
// This says "get me a pointer to (coord) elements past (cursorpos)."
GetCursorPos ( cursorpos + coord );
|
|
|
|
|
|
 |
Cancer Sol

|
Posted: Sun Apr 07, 2013 3:52 pm Post subject: Re: RE:Memory Allocation |
|
|
Thanks, D.
The function GetCursorPos() is in the windows.h header file, so I'm going to have to make my own function for that.
I thought the reason why it wouldn't work was because I was using an array, not because I'm using a pointer xD
I wish references knew what NULL is :/ |
|
|
|
|
 |
wtd
|
Posted: Sun Apr 07, 2013 11:40 pm Post subject: RE:Memory Allocation |
|
|
Oh sweet merciful Jebus! The Windows API and you're new enough to programming that you don't know what a class is? Die with dignity. |
|
|
|
|
 |
Cancer Sol

|
Posted: Mon Apr 08, 2013 10:48 pm Post subject: Re: RE:Memory Allocation |
|
|
wtd @ 4/7/2013, 11:40 pm wrote: Oh sweet merciful Jebus! The Windows API and you're new enough to programming that you don't know what a class is? Die with dignity.
Aww, don't be so mean D:
I'm learning both at the same time... but if it's a bad thing, I guess I'll just learn all the basics first. |
|
|
|
|
 |
Sly14Cat

|
Posted: Wed Apr 10, 2013 6:28 pm Post subject: RE:Memory Allocation |
|
|
Yes wtd, don't be so hard on Cancer Sol. This forum is dedicated to people who can create elaborate programs and those who can't declare a variable yet as well as many in between. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Cancer Sol

|
Posted: Wed Apr 10, 2013 7:34 pm Post subject: Re: RE:Memory Allocation |
|
|
Sly14Cat @ 4/10/2013, 6:28 pm wrote: Yes wtd, don't be so hard on Cancer Sol. This forum is dedicated to people who can create elaborate programs and those who can't declare a variable yet as well as many in between.
Haha, thanks. It doesn't really matter to me though, I think I should learn more before doing this kind of stuff  |
|
|
|
|
 |
Nathan4102
|
Posted: Wed Apr 10, 2013 7:43 pm Post subject: RE:Memory Allocation |
|
|
It might be recommended, but I don't think you HAVE to. I've been working with the winAPI in python, and I know nothing about classes, or string manipulation, or array sorting... |
|
|
|
|
 |
Panphobia

|
Posted: Wed Apr 10, 2013 7:45 pm Post subject: RE:Memory Allocation |
|
|
But it sure helps, and makes things TONS easier. |
|
|
|
|
 |
Cancer Sol

|
Posted: Mon Apr 22, 2013 8:35 pm Post subject: Re: RE:Memory Allocation |
|
|
Panphobia @ 4/10/2013, 7:45 pm wrote: But it sure helps, and makes things TONS easier.
If that's the case, I'll just learn it first XD
Just took a break from compsci for about a week... after I played LoL again, I just couldn't stop playing.
Thank god I'm back to programming though. |
|
|
|
|
 |
Nathan4102
|
Posted: Mon Apr 22, 2013 8:37 pm Post subject: RE:Memory Allocation |
|
|
I was wondering where you went! Glad ya didn't die or something  |
|
|
|
|
 |
QuantumPhysics
|
Posted: Tue Apr 23, 2013 7:37 am Post subject: RE:Memory Allocation |
|
|
Wait, are we still on about ops question or what? |
|
|
|
|
 |
Cancer Sol

|
Posted: Tue Apr 23, 2013 6:30 pm Post subject: Re: RE:Memory Allocation |
|
|
QuantumPhysics @ 4/23/2013, 7:37 am wrote: Wait, are we still on about ops question or what?
What's an ops question?
@Nathan Haha, thanks for caring  |
|
|
|
|
 |
|
|