yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #15681
Re: [Question #657564]: continuous creation and destruction of bodies
Question #657564 on Yade changed:
https://answers.launchpad.net/yade/+question/657564
Jan Stránský posted a new comment:
Hello,
> "b->id=-1;//else it sits in the python scope without a chance to be
inserted again"
this is just that you can re-append erased body if you have it in Python
##
s = sphere((0,0,0),1)
O.bodies.append(s)
#O.bodies.append(s) # would be error
print s.id
O.bodies.erase(0)
print s.id
O.bodies.append(s)
print s.id
##
> and intelligently reallocates free ids for newly added ones
> One explanation could be that your example is too small, i.e. the engine of shared_ptr allocation does not reuse old (freed) memory until it is really necessary, that is after many new insertions
according to the source code, the sentence of "intelligent reallocation"
is not true (perhaps was some time ago), no matter if the example is too
small or not..
However, my comment was really theoretical, practically it has no effect. I have tried the following code, 10e6 append/erase has no significant effect on memory. Assuming sizeof(shared_ptr)=16, it occupies 10e6*16=160e6=160MB, almost nothing)
##
while True:
i = O.bodies.append(sphere((0,0,0),1))
O.bodies.erase(i)
if i%1000000==0:
print i, len(O.bodies)
##
so, go in the direction append/erase without any worries :-)
cheers
Jan
--
You received this question notification because your team yade-users is
an answer contact for Yade.