On 1/12/2012 07:20, Tomas Hajny wrote:
On Thu, January 12, 2012 03:34, waldo kitty wrote:
[TRIM]
without looking at the "code to copy" if i want to override the insert
method, it almost seems that there's a bug if it just throws away the
record we're trying to insert... it would seem that if the code locates
a "duplicate" record, it would properly dispose of unwanted data...
unless i perform the
No. There are two tasks. One is dynamic allocation of the object, the
other is insertion. Although you perform both tasks on one line in your
program, these are two distinct tasks. The insert code cannot know whether
you still may need the (previously allocated) object or not in the very
general case. The insert code doesn't throw anything away - you do it by
not storing the result of the "New (PTLERec, Init (..." to some variable
and only send it as a parameter to a method which may or may not store it
somewhere else.
AHH! i think i understand this now... you are saying that instead of doing
this...
aTLEColl^.insert(New(PTLERec, Init(MySatName, MySatData1, MySatData2, MyCatNbr,
MyEpoch)));
i should do it in two steps like this...
aTLERec := New(PTLERec, Init(MySatName, MySatData1, MySatData2, MyCatNbr,
MyEpoch));
aTLEColl^.insert(aTLERec);
but the the problem still comes of how do i know if the record was inserted into
the list or not? insert doesn't seem to return a true or false on success... i
guess this is where it is required(?) to override the insert method? does
everyone have to override the insert method if they are in duplicates := FALSE
mode? how do they handle the throwing away of the unneeded data??
[TRIM]
2. something else i'm running into is with duplicates:=FALSE, there's
a whole bucket load of records that are not disposed of when i wipe
out the collection... heaptrc hollers right nasty to me about'em on
exit... i can only assume that these are the duplicates but i don't
understand why they are still hanging around if insert or add threw
them away already :/
If you already had them in the collection, they're not added again.
You only dispose records added to the collection at the end, but
these are lost this way. You can also sort this out in the overridden
Insert method (if you don't want to use the newly created record,
dispose it).
i'm looking at this override of the insert method...
as above, i don't know that they are /in/ the collection... i'm
(currently) simply calling the insert method and leaving the work up
to it... if it should be handling this gracefully, it isn't... at least
not in a way that heaptrc likes ;)
It behaves as specified; the responsibility for disposing the duplicates
is on your side (since you allocate them in your code also).
i think i see now...
[TRIM]
i'll probably have broken my code by the time you read this... but i'll
very likely be attempting to implement the logic in my Input_Satellite_List
routine ;) OB-)
Possible, but likely resulting in some useless overhead (computing
performance-wise) if you still intend to use the method Insert in that
case.
yeah, that went over like a lead balloon... i'm digging into the insert method
override, instead... just gotta figure out how to access the epoch in the
current record and the one in the passed record for the decision making
comparison...
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal