ID:151490
 
                                           Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
--------------------------------------------------------------- --------- --------- --------- ---------
/obj/projectile/Del 0.565 292.930 889.350 51743
/atom/movable/Del 210.276 210.592 210.670 55285


    Del()

if(has_effect) // each effect has it's own dedeletion method, sometimes just setting has_effect = 0, then calling Del()
effect()

else
if(parts.len) // i use parts for trails of these projectiles.
for(var/A in parts)
del A

if(loc_null)
loc_null = 1
loc = null

else
..()


The title says it all. Right now i'm working on a project wiwhich uses a lot of temporarily places objects.

The method i'm using to "delete" these objects is posted above. It actually sets the object to null first, then deletes it the next time the Del() process is called(Garbage Collecting?)

However this is taking up quite a bit of CPU, is there another better way to do this?
            if(loc_null)
loc_null = 1
loc = null

else
..()


There's a huge glaring logic error here. However, that doesn't matter, because you really don't need it at all (I have no idea what you're hoping to accomplish with it) and should just replace the whole thing with a simple ..()
In response to Garthor
There's no logic error there as it's intended.

It's setting the location to null, and then stopping the rest of the delete process to continue, which is what I want it to do(That way so a large bulk of projectiles aren't deleted at one time) I was actually thinking of creating a random time frame to delete them..
In response to Axerob
Axerob wrote:
There's no logic error there as it's intended.

This:

if(loc_null)
loc_null = 1


Does not accomplish:

It actually sets the object to null first, then deletes it the next time the Del() process is called(Garbage Collecting?)
By putting that loc=null in Del() (presumably that is, since it's not indented properly), you've kind of missed the boat. You should be moving it to a null location instead of calling del(), not within it. And ..() should always be called in Del() no matter what.

Lummox JR
In response to Garthor
Garthor wrote:
Axerob wrote:
There's no logic error there as it's intended.

This:

if(loc_null)
> loc_null = 1

Does not accomplish:

It actually sets the object to null first, then deletes it the next time the Del() process is called(Garbage Collecting?)

Holy crap I didn't even notice that, honest mistake, thanks.

It happens to the best of us, but geez I can't believe I didn't see that.

@Lummox

Why should ..() always be called? Does something bad happen if it isn't called? I mean I understand that without ..(), the parent process isn't called, nor will any other Del() procedures be called(if I defined them), but not putting ..() in that code is what I want it to do.
In response to Axerob
not putting ..() in there and having 'loc=null' in delete defeats the whole purpose of Del() and setting loc to null O.o
In response to Axerob
Because the deletion won't actually occur without ..() being called.
In response to Popisfizzy
I know this.

Let me explain what i'm trying to do, since no one seems to get it.

I'm trying to make it so it sets your location to null, stopping the deletion process. Then when the deletion process is called again, actually delete it.(Trying to save a little bit of space) I fixed the logic error mentioned by Garthor already, and I've still yet to test to see if my usuage percentages are lower.
In response to Axerob
Axerob wrote:
Let me explain what i'm trying to do, since no one seems to get it.

I'm trying to make it so it sets your location to null, stopping the deletion process. Then when the deletion process is called again, actually delete it.(Trying to save a little bit of space) I fixed the logic error mentioned by Garthor already, and I've still yet to test to see if my usuage percentages are lower.

I get what you're trying to do; the problem is it doesn't work. Setting the loc to null in Del() in order to do a soft deletion is too late. What you need to do instead is set the loc to null instead of calling del(), just like I said (and with the same emphasis as before).

Lummox JR
In response to Lummox JR
Lummox JR wrote:
By putting that loc=null in Del() (presumably that is, since it's not indented properly), you've kind of missed the boat. You should be moving it to a null location instead of calling del(), not within it. And ..() should always be called in Del() no matter what.

Lummox JR

Just a question for curiousity, it does indeed save on cpu by setting an objects loc to null rather than running it through Del()? I see all the logic for getting to the top of the mountain here I just want to know if it's actually worthy enough to do personally.
In response to Bustercannon
Those two operations don't accomplish the same thing.

When you use del, it will null all references to the object.

Setting its loc to null will only remove it from the contents list of whatever its contained in.

For example, you could have a mob with a var referencing its held item, which is in its contents. You could then set that item's loc to null. It will then be removed from the mob's contents. However, it will still be in the mob's held item var and will not be deleted.

Now, of course, setting an object's loc to null is less CPU intensive than calling del on that object. Calling del will have to go to a list of all references and null them.

If there aren't any references to an object, it will be deleted. So, if you have no references to an object (except the contents list of whatever it's contained in), and then you set its loc to null, it will be deleted. (Which would presumably be a more efficient operation than calling del, in that case.)

However, I hope that you understand that those two operations are distinct operations.

Also, this is a really old topic.
In response to Complex Robot
Yeah I know it's old, but I'm looking for every possible route for efficiency so I've been browsing the forums for some knowledge, thank you for answering.