Egon wrote:
if (atomCount == 0) { if (tokenCount > atomArray.length) atomArray = new Atom[tokenCount]; for (int i = tokenCount; --i >= 0; ) atomArray[i] = new Atom(); atomCount = tokenCount; }
This is what I would naturally write.
Let me know if this still is not clear.
>> One warning flag is a 'new' operation which happens in a loop. The >> expense >> is in the reclamation (garbage collecting) more than the allocation. > > Ack. You mentioned this before... is that the only thing I should be aware > of when writing efficient code?
It is *one* of the things.
The fact that Java automatically reclaims unused objects (garbage collects) is a *great* thing.
However, it can be a major source of performance problems. And a source of 'hiccups' in your system ... when your program pauses unexpectedly to reclaim garbage.
Agreed. I have met memory limits. It is important to make sure that variables such as vectors and hashtables are cleared when they are no longer needed.
Programmers who have never worked in a language with explicit heap memory allocation (like alloc/malloc in C) often have a hard time visualizing and appreicating this.
Developers who want to write efficient/systems-quality code still need be be *aware* of when objects are being created ... and avoid doing so unnecessarily.
Agreed. And this is a potential problem with libraries - the object structure is probably not optimised for large memory usage.
Since atomCount == 0, there are effectivly no atom objects in the atomArray. (There will be pointers to the *old* atom objects filling up the array, but we are not using them anymore and they are not important)
Therefore, you can just allocate a new atomArray of the size we need (which will be happen to be filled up with nulls.)
Peter Murray-Rust Unilever Centre for Molecular Informatics Chemistry Department, Cambridge University Lensfield Road, CAMBRIDGE, CB2 1EW, UK Tel: +44-1223-763069
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE. http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Jmol-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jmol-developers
