Solved

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

Posted on 2008-06-15
4
533 Views
Last Modified: 2010-04-21
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
Comment
Question by:DMTrump
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 21789982
I usually do this to clear my array.
SetLength(myarray, 0);
0
 

Author Comment

by:DMTrump
ID: 21790814
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
 

Author Closing Comment

by:DMTrump
ID: 31467391
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
 

Author Comment

by:DMTrump
ID: 21799324
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 143
How To Loop - Python 19 89
Problem to event 3 98
Re-position sub-options beneath the TAB 7 92
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question