Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
simple memory questions #240845
12/12/08 21:24
12/12/08 21:24
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
Hi! I have never worked with memory before, and now I need to copy one awway to another on every frame. So.

Do I have to allocate memory on every frame?
Like

-- Allocate memory for array b
-- Copy array a to array b

or just allocate memory once and then copy all the time?

Or maybe this way?

-- Free space, if b already exist
-- Allocate memory for array b
-- Copy array a to array b

Or I have to free memory only on application close? Would not be there any memory leaks when I copy all the time?


What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: simple memory questions [Re: RyuMaster] #241101
12/14/08 14:39
12/14/08 14:39
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Only allocate the memory once, and free it at the end of the game.

Re: simple memory questions [Re: Tobias] #243915
01/01/09 17:15
01/01/09 17:15
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
Thanks! But do I have to allocate memory, if I use memcpy only?
Currently I have this function, but is is not working, though I get no errors

Quote:
var maparray[MAX_CELLS][MAX_CELLS][3]; //GLOBAL MAP CELL ARRAYS
var maparray2[MAX_CELLS][MAX_CELLS][3];

.... here arrays are filled with info and then....

memcpy(&maparray2, &maparray, sizeof(var) * MAX_CELLS * MAX_CELLS * 3);



What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: simple memory questions [Re: RyuMaster] #245354
01/09/09 16:34
01/09/09 16:34
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
I guess it is not that simple..
I'm trying copying those arrays for a long time, still it is not working.

I have found this in the manual:

Quote:
Be aware that arrays are internally treated as a pointer to a memory area. So, sizeof(any_array) always returns 4 because that is the size of a pointer.


This is only info regarding arrays, and so I'm using formula to get size.

Maybe arrays have some more restrictions, their memory is not aligned well, they can not be copied this way, and I'm wasting my time?


What kills me not, that makes me stronger.

***Working on RPG/RTS***
Re: simple memory questions [Re: RyuMaster] #245358
01/09/09 16:43
01/09/09 16:43
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
I think the problem is this:

sizeof(var) * MAX_CELLS * MAX_CELLS * 3

there was a thread and also a mention in the manual that it does not work this way. Try

(int)sizeof(var) * MAX_CELLS * MAX_CELLS * 3

or simply

4 * MAX_CELLS * MAX_CELLS * 3

Re: simple memory questions [Re: Tobias] #245444
01/09/09 22:56
01/09/09 22:56
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

Joined: Aug 2006
Posts: 155
Thanks a billion! I've searched all topic, just how could i miss it?


What kills me not, that makes me stronger.

***Working on RPG/RTS***

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1