Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, howardR), 472 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Any tricks to releasing memory used by ent_clone? #409198
10/13/12 17:04
10/13/12 17:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hiya all.

Is there any 'trick' or workaround that will allow me to
'undo' or 'reverse' an ent_clone?

AFAIK the only way to release the memory consumed by an ent_clone
is to ent_remove the whole entity. I would like to avoid this.

I wish to be able to be able to perform ent_clone on the same
entity multiple times, but only use one ent_clone worth of memory.

EG:
ent_create; ent_clone; wait(?); while{ ENT_UNCLONE; ent_morph; ent_clone; wait(?); }

Any ideas anyone? Thanks all.

For further details, see THIS thread...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Any tricks to releasing memory used by ent_clone? [Re: EvilSOB] #409200
10/13/12 17:32
10/13/12 17:32
Joined: Apr 2008
Posts: 2,488
ratchet Offline
Expert
ratchet  Offline
Expert

Joined: Apr 2008
Posts: 2,488
Change your 3D engine !
just kidding laugh

Last edited by ratchet; 10/13/12 17:32.
Re: Any tricks to releasing memory used by ent_clone? [Re: ratchet] #409254
10/14/12 12:12
10/14/12 12:12
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
For releasing the mesh and textures call ent_purge, for removing the entity from the cache use the level_mark and level_free.

Re: Any tricks to releasing memory used by ent_clone? [Re: Spirit] #409325
10/15/12 16:48
10/15/12 16:48
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Not necessary. Cloned entities do not occupy the cache, so the memory is released with ent_remove - and I can not see any problem with that. No trick required.

Re: Any tricks to releasing memory used by ent_clone? [Re: jcl] #409346
10/15/12 20:41
10/15/12 20:41
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
OK... no one seems to be able to understand my question... So I will try again.

Code:
#include <acknex.h>
#include <default2.c>
//
void main()
{
	wait(1);		level_load(NULL);		wait(1);		camera.x = -150;		random_seed=100;
	//--------------------------------------------------------------------------------------
	//
	ENTITY* ents[100];		int i,v;		CONTACT* c;		VECTOR tmpV;
	//--------------------------------------------------------------------------------------
	for(i=0; i<100; i++)	
	{
		ents[i]=ent_create(SPHERE_MDL, vector(0,random(100)-50,random(100)-50), NULL);
		ent_clone(ents[i]);
		//
		v = integer(random(ent_status(ents[i],0)));
		c = ent_getvertex(ents[i], NULL, v);
		tmpV.x = c.v.x;	tmpV.y = c.v.z;	tmpV.z = c.v.y;
		vec_scale(tmpV, 1.5);
		c.v.x  = tmpV.x;	c.v.z  = tmpV.y;	c.v.y  = tmpV.z;
   	ent_setvertex(ents[i], c, v);
	}
	//--------------------------------------------------------------------------------------
	while(1)
	{
		for(i=0; i<100; i++)	
		{
			switch(integer(random(4)))
			{
				case 1:
					ent_morph(ents[i], CUBE_MDL);
					ent_clone(ents[i]);
					break;
				case 2:
					ent_morph(ents[i], SPHERE_MDL);
					ent_clone(ents[i]);
					break;
				default:
					// just do vertex displacement
			}
			//
			v = integer(random(ent_status(ents[i],0)));
			c = ent_getvertex(ents[i], NULL, v);
			tmpV.x = c.v.x;	tmpV.y = c.v.z;	tmpV.z = c.v.y;
			vec_scale(tmpV, 1.1);
			c.v.x  = tmpV.x;	c.v.z  = tmpV.y;	c.v.y  = tmpV.z;
			ent_setvertex(ents[i], c, v);
		}
		//
		wait(1);
	}
	//--------------------------------------------------------------------------------------
	sys_exit(0);
}


HOW can I fix the memory leak in this code? CAN I fix the memory leak in this code?

ALL instances of ent_clone and ent_morph are REQUIRED! Ent_remove is NOT ALLOWED!!

Hopefully someone can just ANSWER my questions without trying to re-write my code...
This is just SAMPLE code, I cant post 100Mb of project here...
This SAMPLE is just to convey my problem, and the limitations the answers
are constrained by...


PS:: I have tried playing with ent_purge and ent_reload, with no sucess,
but that doesnt mean Im not using them wrong...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Any tricks to releasing memory used by ent_clone? [Re: EvilSOB] #409352
10/15/12 21:55
10/15/12 21:55
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Originally Posted By: jcl
Not necessary. Cloned entities do not occupy the cache, so the memory is released with ent_remove - and I can not see any problem with that. No trick required.


Just use ptr_remove, why wouldn't it be allowed? If you need to keep any parameters, save them temporarily. Example:

Change

ent_morph(ents[i], CUBE_MDL);
ent_clone(ents[i]);

to

vec_set(tmpV,ents[i].x);
ptr_remove(ents[i]);
ents[i]=ent_create(CUBE_MDL, tmpV, NULL);
ent_clone(ents[i]);


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Any tricks to releasing memory used by ent_clone? [Re: Superku] #409367
10/16/12 07:14
10/16/12 07:14
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Correct. Only for entities use ent_remove, not ptr_remove. Both do the same, just for clarity reasons.

Re: Any tricks to releasing memory used by ent_clone? [Re: jcl] #409371
10/16/12 08:39
10/16/12 08:39
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I CANT USE ENT_REMOVE! Can I make it any more clear!

I have other functions and code that store the entities by entity pointer,
not by their position within the 'ents' array.

So if I do an ent_remove/ptr_remove then those functions/actions will be
pointing to a no-longer-valid address, or even a different entity altogether.
This is not good...

Also, I am currently using ent_morph because it is MUCH faster then performing
an ent_remove & ent_create combo. I will be processing the entities in
'batches' and if I use the ent_create process I get stuttery fps
due to 20+ ent_create's in a single frame. Ent_morph doesnt cause this problem.


If the answer is "... it CANNOT be done...", then someone say so... please.
(but dont lie, I want the truth!)


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Any tricks to releasing memory used by ent_clone? [Re: EvilSOB] #409372
10/16/12 08:48
10/16/12 08:48
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
Just to rewrite your question, so jcl / others can understand it:

You have more or less this coding:
Code:
ent = ent_create(..)
ent_clone(ent);
while(1) {
  ent_morph(ent,...); //much faster and safer than ent_remove / ent_create combo
  ent_clone(ent);
  wait(1);
}



Additionally you have several external references to "ent", and therefore do not want to invalidate the pointer (besides it's pretty nonsense to "recreate" an entity - with all known sideeffects, e.g. restarted action, stopped functions, and slow processing).

Your question is, if:
1) With the ent_morph action, the reserved memory for the previously cloned model is freed
2) If not: Does a second call (e.g. to subsequent calls of ent_clone) free the memory of the first call?
3) If not: If there is a possiblity to free the extra memory reserved by a clone instruction after a morph instruction, without removing and recreating the entity.

correct me if i'm wrong

FYI: After a clone instruction the complete vertex / index buffer is copied. I do not think that it is possible to go "back to standard" (so releasing the changed parts). But: After a morph instruction the complete copied vertex / index buffer should be released, and your given code should not create any memory leak at all..

FYI 2: If the memory is not freed after the morph instruction, this is just a bug for me. Actually I highly doubt that ent_remove will recognize the "old" vertex buffers after some morph / clone instructions and delete them. Ent_Morph should detect if the current model is cloned, and delete the buffers accordingly if necessary..

Last edited by TechMuc; 10/16/12 08:52.
Re: Any tricks to releasing memory used by ent_clone? [Re: EvilSOB] #409373
10/16/12 08:51
10/16/12 08:51
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Evilsob: If you have other functions that access the entities by pointer, then why don't you change those functions so that they access the entities by array index instead, if that is what you need? That should be a matter of five minutes.

Of course ent_remove is slower than ent_morph because ent_remove releases the clone, which is just what you asked for.

There are obvious and simple solutions to your problem. You just have to use them. Behave like a programmer and solve your problem instead of whining about it.

Page 1 of 2 1 2

Moderated by  old_bill, Tobias 

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