Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

Trouble with Dynamic Arrays in Delphi 2007 -- Causing illegal pointer and/or out of mem errors

I'm rewriting an application that has worked a long time and well using static arrays but we now need to handle much larger data sets of variable size:  The app is a statistical analysis program and in the course of the analysis process I transform the data through about 50 arrays - most of type extended.

As different sets of data are loaded for processing I size the collection of dynamic arrays with a procedure that includes sets of lines like this:  (one for eacy of the many arrays)   Many of the arrays are two dim as shown below - some are single dim - but all are of varrying size depending on the data set.

    if isRaDc<>nil then  isRaDc:=nil;
    SetLength(isRaDc, cpnts, creps);                // [0..callibration_pnts, 0..callibration_reps] of Extended;
      for I := 0 to high(isRaDc) do for j := 0 to high(isRaDc[i]) do isRaDc[i,j]:=0.0;

In the above lines - if I leave out the nil statement I soon get an "out of memory" error after several runs.
If I include it - either with or without several different ways of making it conditional, I get an "illegal pointer operation error" upon the second or third run - depeding on the arrays sizing.

Should I be doing something to force garbage collection after each run - If so I have no idea how?
0
DMTrump
Asked:
DMTrump
  • 3
1 Solution
 
TheRealLokiSenior DeveloperCommented:
I usually do this to clear my array.
SetLength(myarray, 0);
0
 
DMTrumpAuthor Commented:
A good method - but subbing that for my previous nil assignment did not prevent the "illegal pointer operation" error.  I can't investigate any further tonight, but will tomorrow morning.  

Previous experimentation however, showed that the illegal pointer operation occurred not on a particular array, but after a certain approximate number of reset operations.  Can you think of other causes of illegal pointer message that I could look for in my code?

Perhaps I need to close this question (award you the points) and open a new more general one about causes of illegal pointer messages?

0
 
DMTrumpAuthor Commented:
A good solution to the question I asked - but it didn't solve my problem.

experimenting further I was able to determine that the problem is elsewhere in my code.  Wish me luck!
0
 
DMTrumpAuthor Commented:
TheRealLoki,

Thanks again for your help - being able to determine that the problem was NOT associated with the dynamic array routines - (no one posted a "you idiot!" appraisal of my code snippet) gave me the information I needed to go looking in the other places - and I found the problem.

The take-away, for anyone else who might stumble on this is that errors may (in fact often do) show up in obscure unrelated code because your real error has set up conditions that cause a reportable error condition (I use EurekaLog) at some other point in your code.  That's a good thing to remember!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now