Re: array with same value all the time?



"Sonnich" <sonnich.jensen@xxxxxxxxxxxxxx> schreef in bericht
news:1143474738.112955.64510@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi!

I have a project where I collect data into this:

TDataRec = record
Name: string[81];
RecordTime: TDateTime;
Value: double;
end;

I have an array ot that; where I add data when I get it (it happens in
a thread) - there is a TCristicalSection to avoid multiple instances
using it.
There is a procedure in the thread, which adds data.

The execute part looks at data, when there is enough, it goes in,
processes data, and delete them (that means - moving them, and setting
the array that much shorter using SetLenght) - usually it is cleared to
0 size.

{ delete used data }
i := iUsedData;
while i < Length(aData) do
begin
aData[i-iUsedData] := aData[i];
Inc(i);
end;
SetLength(aData, Length(aData) - iUsedData);

My problem is that sometimes for some reason, the Value is the same for
all records - that is possible, that it might happen once in a million
years, but not once a day as I get it. The name is the same, but the
timestamp is chaning correctly. It is just the recieved value, which
repeats itself.


That behaviour can not be the result of the code you publish above, which
just shifts data. I would say that it happens at the point where the data is
collected. You say consecutive records have Name and Value identical but the
timestamp changes. You do not show code of the data collection part.

Is there a particular reason to use a dynamic array rather than a Tlist
(with objects instead of records)? Adding and deleting would be more
elegant.

Tom


.



Relevant Pages

  • Re: About Thread Completion Notify.
    ... This is the reason that i must keep track of the threads and they have to ... i remove it from the array. ... > (which you probably don't since you are servicing requests in separate ... you shouldn't have a need for waiting on events. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: please confirm something (jdbc)
    ... of its internal buffer so that will double the amount of memory that you need. ... That's the reason I wrote my own dynamic byte array ... Given all the memory re-allocation that goes on inside the ByteArrayOutputStream anyway, I'm not sure that one more allocation is all that much extra overhead. ... If I have two ways of coding something, and I know that one will definitely use less memory (or be quicker for whatever reason) then I will choose the one "better" one. ...
    (comp.lang.java.programmer)
  • Re: Help needed on Arrays
    ... What does the SQL Stored Procedure do? ... Is there a specific reason you want to create an extra ... be in an array or arraylist. ... The language is vb.net 2005. ...
    (microsoft.public.vsnet.general)
  • Re: what is the best datatype for..
    ... array that will be scanned searching for the index value, ... It also won't be flexible if the input data changes for any reason, since the implementation itself is so dependent on the input data. ... Calling the dictionary solution "inefficient" is just plain dumb; it might not be quite as fast as a straight array lookup, but it's not like it's a _slow_ design. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: array with same value all the time?
    ... TDataRec = record ... the array that much shorter using SetLenght) - usually it is cleared to ... SetLength- iUsedData); ... timestamp changes. ...
    (comp.lang.pascal.delphi.misc)