0 registered members (),
950
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Expert
|
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
Expert
|
Expert
Joined: Apr 2008
Posts: 2,488
|
Change your 3D engine ! just kidding
Last edited by ratchet; 10/13/12 17:32.
|
|
|
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
OP
Expert
|
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.
#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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
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: jcl]
#409371
10/16/12 08:39
10/16/12 08:39
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
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
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
Just to rewrite your question, so jcl / others can understand it: You have more or less this coding:
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.
|
|
|
|