Solved

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

Posted on 2008-06-15
4
528 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
Comment Utility
I usually do this to clear my array.
SetLength(myarray, 0);
0
 

Author Comment

by:DMTrump
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now