Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EOutOfMemory using TIBQuery

152 views
Skip to first unread message

Eduardo Murmis

unread,
May 26, 2008, 9:49:26 AM5/26/08
to
Hello:

I am using Delphi 5 and IBX and I have the following problem.

Sometimes, I open a table using a TIBQuery component, and then I access many
records. As I am doing Next (or sometimes Prior), the component allocates
memory. But in some cases, it occurs an EOutOfMemory error.

The error happens in the unit IB.pas, in the following procedure:

procedure IBAlloc(var P; OldSize, NewSize: Integer);
var
i: Integer;
begin
ReallocMem(Pointer(P), NewSize);
for i := OldSize to NewSize - 1 do
PChar(P)[i] := #0;
end;

I know this is a known bug of IBX and the only solution I found is to set
the Unidirectional property of TIBQuery to True. This is a good solution but
only if you access the table doing only Next and you never do Prior. But
this is not my case allways, so I need another solution.

I also know that this bug was corrected in future versions of IBX but I
can´t upgrade my Delphi now. So my question is if anybody knows if there is
some way to modify some lines of code of the sources of IBX and correct this
bug in the version of IBX which works with Delphi 5 (I think is IBX 5.04).

Thanks in advance

Eduardo


Bill Todd [TeamB]

unread,
May 26, 2008, 2:06:51 PM5/26/08
to
Since you are iterating through a large number of rows consider moving
the code to a stored procedure. It will execute faster and cause less
network traffic.

--
Bill Todd (TeamB)

Eduardo Murmis

unread,
May 26, 2008, 5:23:16 PM5/26/08
to
Thank you for your answer but I am not always iterating. I simplified the
case only as an example to explain my problem, but I have many cases wich
are different and it is not a solution to write stored procedures.

Eduardo

"Bill Todd [TeamB]" <n...@no.com> escribió en el mensaje
news:483afc3b$1...@newsgroups.borland.com...

Eduardo Murmis

unread,
Jun 3, 2008, 4:29:53 PM6/3/08
to
So... :-( nobody knows if there is some way to modify some lines of code in
the sources of IBX and correct this bug in the version of IBX which works
with Delphi 5 (I think is IBX 5.04)?

I saw Jeff Overcash is in this newsgroup and I think he is the original
author of IBX components. Jeff: Did you read this? Do you know please what
can I do to solve this problem?

Thanks in advance again!

Eduardo

"Bill Todd [TeamB]" <n...@no.com> escribió en el mensaje
news:483afc3b$1...@newsgroups.borland.com...

Jeff Overcash (TeamB)

unread,
Jun 3, 2008, 7:18:47 PM6/3/08
to
Eduardo Murmis wrote:
> So... :-( nobody knows if there is some way to modify some lines of code in
> the sources of IBX and correct this bug in the version of IBX which works
> with Delphi 5 (I think is IBX 5.04)?
>
> I saw Jeff Overcash is in this newsgroup and I think he is the original
> author of IBX components. Jeff: Did you read this? Do you know please what
> can I do to solve this problem?
>
> Thanks in advance again!
>
> Eduardo
>

There isn't a bug here. You are just running out of contiguous memory. There
are no lines of code to change. IBX requires a contiguous area of memory to
store the data. Every time you resize that memory (based on the BufferCache
property) you need 2 times the actual memory you are needing to extend to during
the reallocate phase. The only thing you can try is to increase the
BufferChunks very large so it doesn't have to reallocate over and over.

IBX's memory model has always worked this way and has never been changed to a
different model that would get around needing contiguous memory.


--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)

Eduardo Murmis

unread,
Jun 5, 2008, 3:05:42 PM6/5/08
to
Jeff:

Thank you for your answer.

I already tried changing BufferCacheSize but the result is the same.

You said that every time you resize the memory "you need 2 times the actual
memory you are needing to extend to during the reallocate phase". As I
understand, when I execute Next, if I reach the maximum 1000 bytes allocated
and I need more memory, then IBX allocates 2000 bytes of contiguous memory.
To do this, IBX needs to find 4000 bytes of contiguous memory. After some
more Next instructions (and perhaps some Prior instructions too), it will
need to allocate 3000 bytes and then it will need fo find 6000 bytes of
contiguous memory.

Suppose that I open a query using a SELECT statement that retrieves 1000000
records (and suppose I need 1000 bytes per record) and then I make a loop
(while not EOF do ...) because I need to check some complex condition on
every register. Then, to finish the loop, I will need aprox. 1GB of
contiguous memory. But, after some Next instructions, I will get the
EOutOfMemory error. Is this right?

So I think... Is there a way to do this, seting a maximum amount of memory
to use per query and when I reach this maximum, then I retreive a new record
but I "loose" another record which was in memory. Perhaps this is not a good
idea because of performance or for another reason. I don´t know.

Do you have any suggestion to do this "while not EOF" loop of a big query? I
remember that in this loop there are Next and Prior instructions and so to
use Unidirectional:=True is not a solution.

Eduardo

"Jeff Overcash (TeamB)" <jeffov...@mindspring.com> escribió en el mensaje
news:4845d164$1...@newsgroups.borland.com...

Jeff Overcash (TeamB)

unread,
Jun 5, 2008, 6:58:46 PM6/5/08
to

No there is no way to do any of the things you are asking for. Each time a
reallocation happens it will be the old size + size needed to hold the next
BufferChunks # of records + the old memory, then the old memory is copied to the
new memory block and then the old memory block is freed.

Eduardo Murmis

unread,
Jun 6, 2008, 6:39:26 PM6/6/08
to
Well, that is really bad news, but life is like it is. :-)

Thank you!

Eduardo

"Jeff Overcash (TeamB)" <jeffov...@mindspring.com> escribió en el mensaje

news:4848...@newsgroups.borland.com...

Will Honor

unread,
Jun 25, 2008, 5:54:06 AM6/25/08
to
Eduardo Murmis wrote:

> Hello:
>
> I am using Delphi 5 and IBX and I have the following problem.

> But in some cases, it occurs an
> EOutOfMemory error.
>


Have you tried using FastMM? it is better than the default memory
manager in Delphi 5 and will cut down on the amount of memory
fragmentation. It may give you more mileage before this error occurs.

Regards,
Will.

http://sourceforge.net/projects/fastmm/

0 new messages