Libbulletjme.so chashed after application destroy,

I rewrite the same piece of code 2-3 times a day for reasons of refactoring, for example:

step 1:

 for(key String : players.keySet()){
        players.get(key).method();
 }

step 2:

   for(key String : players.keySet())
      Player player = players.get(key);
      player.method();
   }

step 3:

Player player;
 for(key String : players.keySet())
          player = players.get(key);
          player.method();
 }

step 4:

Player player;
for(key String : players.keySet())
          player = players.get(key);
          player.method();
}
player = null;

1 Like

Step 3 and 4 are a waste of time. They provide no benefit and make the code potentially more buggy… as your step 4 indicates.

When you are more experienced, you will find in these simple cases you will just write things correctly the first time instead of having to redo it over and over.

1 Like

Also…

Step 5:

for( Player player : players.values() ) {
    player.method();
}
3 Likes

Optimization:

  1. Does not create a variable in a loop.

  2. Allocate memory one time.

  3. Clear memory.

    //allocate memory one time
    Player player;
    for(key String : players.keySet()){
    //use already exist variable players
    player = players.get(key);
    player.method();
    //method 2 method 3 method 4
    }
    //clear memory
    player = null;

1 Like

You literally have absolutely no idea what you are talking about.

Your final solution does more work with the same amount of memory. You have no understanding at all of what the compiler is doing and if you were even on my team (ugh) I’d have to watch your coding practices like a hawk… because you are the worst kind of coder: you speak with authority on things you are clueless about.

3 Likes

We conducted many tests of performance and memory.[quote=“danielp, post:27, topic:39048”]
Doesn’t clear any memory - it drops a reference to memory that’s still being held by the object in the map, which would have happened as soon as your method exits anyway. The only way memory gets cleared in Java is when the GC runs and clears objects that are no longer referenced anywhere (or, more correctly, no longer reachable).
[/quote]

Yes, at last we have finalizer thread + gc. crashed by time(!).
It is easier to think in advance of such things.
You need to look for various low-level optimizations for java

1 Like

Except that (a) these are micro-optimizations, which are almost certainly 100% of the time a bad idea in Java because they clutter your code and Java’s JIT will optimize everything on the fly and (b) none of them actually do what you think they’re doing.

  1. Doesn’t “create a variable.” It assigns to a local variable “slot” that was allocated on the stack as soon as the method was called. Local variables are resolved at compile time and stack space is allocated once as soon as the method is entered.

  2. Doesn’t allocate memory - it assigns a reference to preexisting memory to a variable. No new memory is allocated.

  3. Doesn’t clear any memory - it drops a reference to memory that’s still being held by the object in the map, which would have happened as soon as your method exits anyway. The only way memory gets cleared in Java is when the GC runs and clears objects that are no longer referenced anywhere (or, more correctly, no longer reachable).

@pspeed’s way is the most efficient and least error-prone by far.

3 Likes

Yes, but you have no idea what you are doing and so your conclusions will be incorrect with whatever you saw.

I mean, I know this 100% for a fact because you are so totally and completely wrong about this subject. Like, so obviously and totally and completely wrong. You have no idea what you are talking about and haven’t even bothered to look into it.

If you were on my team I’d be actively trying to get you fired.

I’ve been a software developer professionally for 27 years and run many many teams. You are the very worst kind of person to have on a team.

2 Likes

I think you are a lost cause but I will try to be clear.

(1) no memory is allocated here. Look at the byte code.

(2) no memory is cleared here. You are doing a wasteful stack operation by replacing the stack element with a null.

Moreover, you have needlessly leaked scope. By this idiom in general, you have potentially prevented the object from being GC’ed at the end of the loop (if it was created in the loop… it’s not here but the whole idiom you use is broken so I thought I would mention it).

You should keep loop-only variables inside the loop. It’s better for every reason and there are no down sides. The fact that you think there are means you do not understand what is actually happening.

2 Likes

I’m a businessman - competitors cut us the internet wire with an ax.
I have no doubt - “Forbes”.
My blog: how to open central bank: http://worldcompanylist.blogspot.ru/2017/07/blog-post.html

As you know your knowledge is based on the knowledge of previous generations - I did not invent these things.

1 Like

Yes, I see. You are definitely not a coder.

It makes sense now… because you have no idea what you are talking about. Even a brief glance in the byte code would show how full of crap you are.

2 Likes

No. My knowledge is based on actually knowing what is going on. I’ve looked at the compiler. I’ve looked at byte code. I do not need to guess because I can see the facts plainly.

3 Likes

i write a framework and service-market with 30-60 thousand users. I studied this at university for 5 years. I think im programmer in fact.
You just criticize my coding style.

1 Like

:disappointed_relieved:

2 Likes

A similar question:

of crap you are.

:smiley::laughing::laughing::joy:

1 Like

Question… How does a blog post that has a laundry list of super high level items that comes across like the basic definition of what a bank does qualify your knowledge in the area of software development?

It’d be like me saying “I’m a brain surgeon! Here’s my qualifications: http://www.bbtoystore.com/mm5/pokemon/PK_Tree_single.jpg .”

Just curious where the logic train on that comes from.

2 Likes

LOL. You didn’t even understand that link… because it 100% supports what I’m saying and says your way is wrong.

Hilarious.

3 Likes

… That article agrees with pspeed though.

So, since str is not used outside the loop, the smallest possible scope for str is within the while loop.

So, the answer is emphatically that str absolutely ought to be declared within the while loop. No ifs, no ands, no buts.

That’s from the Stack Overflow link you just pasted…

3 Likes

Why do you spend your time to him? :slight_smile: I think he’s just a troll. :slight_smile:

3 Likes

I’m killing time before a team meeting.

But also, I’m trying to make sure that other unsuspecting folks don’t follow this guys examples.

5 Likes